JDK-8227202 : clarify Class.isEnum() doc
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-07-03
  • Updated: 2019-11-27
  • Resolved: 2019-07-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b05Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
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.

Comments
Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-July/061193.html
03-07-2019