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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Not an Issue
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: