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

clarify Class.isEnum() doc

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 14
    • None
    • core-libs
    • b05

      Consider:

          enum MyEnum {
              A,
              B { void foo() { } }
          }

      Then:

              MyEnum.A.getClass().isEnum() ==> true
              MyEnum.B.getClass().isEnum()) ==> false

      This is correct and is as specified by JLS 8.9.1. However, it's counterintuitive, as one might reasonably expect enum constants to be instances of the enum class. This isn't the case, as enum constants with method bodies are instances of an anonymous subclass of the enum class, and isEnum() is [correctly] false for such subclasses.

      This might be worth noting in the Class.isEnum() method doc.

            darcy Joe Darcy
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: