JDK-5008260 : @Override should be generalized from 'superclass' to 'supertype'
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-03-04
  • Updated: 2014-02-26
  • Resolved: 2011-07-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 rcFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
###@###.### 2004-03-04

J2SE Version (please include all output from java -version flag):
  java version "1.5.0-beta2"
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
  Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)

Does this problem occur on J2SE 1.3.x or 1.4.x?  Yes / No (pick one)
  N/A

Operating System Configuration Information (be specific):
  Windows 2000 Professional SP2

Bug Description:
  Using @Override on a method from an implemented interface causes 
  compilation to fail. This seems a shame, as it would be particularly 
  useful when overriding the method with a different return type in an 
  interface or abstract class - useful because a mistake made in doing 
  so might not cause a compiler error yet still may not be what the 
  programmer had intended.

Steps to Reproduce (be specific):

  Compile Food.java (below) using -source 1.5.  Note that removing the 
  @Override annotations allows compilation to succeed.


Test program: Food.java

public interface Food {
       Food getInstance();
}


interface Cheese extends Food {
       @Override Cheese getInstance(); // compilation error
}

class Biscuit implements Food {
       @Override public Food getInstance() { return new Biscuit(); } // compilation error
}

abstract class Fruit implements Food {
       @Override public abstract Fruit getInstance(); // compilation error
}

class Apple extends Fruit {
       @Override public Apple getInstance() { return new Apple(); } // ok
}
Elided java.net submission since compiler fixes are not accepted
for specification issues.

Comments
EVALUATION The JLS should say: ... If a method is annotated with this annotation type a compile-time error will occur unless either the method is override-equivalent to a method in Object, or the method does override or implement a method declared in a supertype.
2006-05-11

EVALUATION The specification of java.lang.Override should be: * Indicates that a method declaration is intended to override a * method declaration in a supertype. If a method is annotated with * this annotation type compilers are required to generate an error * message unless either the method is override-equivalent to a method * in {@linkplain Object}, or the method does override or implement a * method declared in a supertype.
2006-01-13

EVALUATION I believe the examples in the bug should work. Nothing in the spec indicates otherwise. There is some question if marking the initial implementation of an interface method in a class as an override is desirable. ###@###.### 2004-08-03 The FAQ in the JSR175 spec indicates that this behavior is deliberate. Far be it from me to question the wisdom of the JSR175 EG. ###@###.### 2004-08-04
2004-08-03