JDK-6326485 : Compiler does not enforce rule that interfaces may not use @Override
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-09-20
  • Updated: 2010-04-02
  • Resolved: 2006-05-11
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
Consider:

public interface Name<T extends Name> extends Comparable<T> {
  @Override String toString();
  @Override int compareTo(T o2);
} 

Compiling produces the following result:
>javac Name.java
Name.java:3: method does not override a method from its superclass
  @Override int compareTo(T o2);
   ^
1 error

javac correctly reports the annotation on compareTo(.) as an error. However, it passes the annotation on toString(). This contradicts JLS 3, section 9.6.1.4, which states that interface methods may never use @Override (See http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6.1.4.).


REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION The specification will be revised in 6399361.
11-05-2006

EVALUATION A bug. Internally, javac considers java.lang.Object a superclass of interfaces. In most cases this is fine, however this means that the check for @Override should see if the owner is an Interface and reject the program in this case.
21-09-2005