Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6326485

Compiler does not enforce rule that interfaces may not use @Override

XMLWordPrintable

    • 5.0
    • x86
    • windows_xp

      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.

            ahe Peter Ahe
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: