No compiler error if enum has a method that is override-equivalent to compareTo(Object)

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P2
    • None
    • Affects Version/s: 6
    • Component/s: tools
    • generic
    • generic

      There is an JLS3 statement (8.9 Enums):
      "It follows that enum type declarations cannot contain fields that conflict with the enum constants, and cannot contain methods that conflict with the automatically generated methods (values() and valueOf(String)) or methods that override the final methods in Enum: (equals(Object), hashCode(), clone(), compareTo(Object), name(), ordinal(), and getDeclaringClass())."

      As I understand, javac should report error, if we define such fields or methods.
      Actually it does report compile-time error for all these, except compareTo(Object).

      For example:

      enum TestEnum {
          a1, a2, a3;
          public void compareTo(Object obj) {
          }
      }

      no problem is reported by javac.

            Assignee:
            Peter Ahe
            Reporter:
            Victor Rudometov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: