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

clarify Class.isEnum() doc

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 14
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b05

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: