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

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

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • CPU:
      x86
    • OS:
      windows_xp

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: