Community
Participate
Working Groups
Static methods cannot be overridden, but only hidden by a derived class. Therefore the @Override annotation is incorrect for static method in a derived class, even if a static method with the same signature exists in the base class. Until Eclipse 3.1, this mistake was simply disregarded. With Eclipse 3.2 (certainly with 3.2.1 and later) this treated as an error, even if the Java compiler (at least Sun's Java 5 compiler) does not treat this as an error. I suspect that the Java 6 compiler is more strict and also think that is OK anyway to mark this as an error. My issue is that the error message that looks something like this: "The method xYzzy() of type DerivedClass must override a superclass method" If the affected method is static, I suggest to use an error message like this: "Static method xYzzy() cannot be overridden, but only hidden. Remove @Override annotation." Alternatively, the @Override annotation could be flagged with an error message like this: "Static methods cannot be overridden, but only hidden. Remove @Override annotation."
On following: class Base { public static void foo() {} public void bar() {} } public class X extends Base { public static void foo() {} public void bar() {} } Neither javac6 or javac7 will report missing@Override annotation. Neither do we in 3.4M7.
I agree our error message needs to be read twice to figure, but essentially it tells the truth in saying that X#foo() does not override Base#foo() (since static methods do not override). I think our current message is tolerable. And yes javac6 and javac7 also report this issue.
Verified for 3.4RC1.
My complaint was about the following situation: class Base { public static void xYzzy() {} } public class X extends Base { @Override public static void xYzzy() {} } In this situation, the message simply does not make sense. Sorry for the unclear bug report; I should have included an example when I reported.
In theory you could imagine nuancing the error message, but in practice the way it reads today is not wrong; I guess it depends whether you think 'static' is a stronger statement than '@Overrides'. I wouldn't change the message for such a small nuance. Closing again.