Community
Participate
Working Groups
20050104: Steps to reproduce: - Create interface ITest<A extends Map & List, B extends Collection, C> with method A getA() returning null - Implement interface in a test class - Add @Override annotation to the overridden getA() -> Unnecessary compiler problem that method must override method from superclass -> Message should rather say supertype instead of superclass
Test case: public interface I<A> { A getA(); } class X<A> implements I<A> { @Override public A getA() { return null; } }
No, the compiler's current behavior is correct with respect to the specs. The javadoc of @interface Override also only talks about "superclass" and not about "supertype". The JLS3 preview says (9.6.1.4 Override) explicitly: "Note that if a method overrides a method from a superinterface but not from a superclass, using @Override will cause a compile-time error." IMO, the specs are seriously broken in this matter, since they make a difference between interface and abstract class methods: interface I { void run(); // delete and everything's fine } abstract class C { abstract void run(); // delete and you'll get a compile error } class X extends C implements I { @Override public void run() { } }
We will stick to the spec.