0

The Vector3 class contains this:

public final boolean set(float x, float y, float z) {
    setX(x);
    setY(y);
    setZ(z);
    return true;
}

The Vector4 class contains this:

public boolean set(float x, float y, float z, float w) {
    setX(x);
    setY(y);
    setZ(z);
    setW(w);
    return true;
}

No errors. Why?

2 Answers2

4

You didn't override set in Vector4. You overloaded it. Vector4's set method has 4 parameters but Vector3's set method has 3 parameters. There is no error because no method is attempting to override the final set method in Vector3.

rgettman
  • 176,041
  • 30
  • 275
  • 357
1

You did not extend the method, but instead you have created a new overloaded method with a different signature. Although they may have the same name, the fact that their parameter lists are different makes them distinct methods.

Had you attempted to override Vector3.set(float, float, float) with:

public boolean set(float x, float y, float z)

in Vector4, there would have been an error at compilation.

nanofarad
  • 40,330
  • 4
  • 86
  • 117