JDK 14 RFR of JDK-8227202: clarify Class.isEnum() doc

Joe Darcy joe.darcy at oracle.com
Wed Jul 3 21:24:52 UTC 2019


Please review the patch below to address

     JDK-8227202: clarify Class.isEnum() doc

To condense a long story (see 
there are cases where the Class object of an enum constant is *not* the 
Class object of the declaring enum type. While this is the specified 
behavior, it can be surprising and the paragraph of added text is 
intended to explain the situation.



--- a/src/java.base/share/classes/java/lang/Class.java    Wed Jul 03 
15:46:48 2019 -0400
+++ b/src/java.base/share/classes/java/lang/Class.java    Wed Jul 03 
14:22:28 2019 -0700
@@ -3491,9 +3491,16 @@
       * Returns true if and only if this class was declared as an enum 
in the
       * source code.
+     * Note that if an enum constant is declared with a class body,
+     * the class of that enum constant is an anonymous class and
+     * <em>not</em> the class of the declaring enum type. The {@link
+     * Enum.getDeclaringClass} method can be used to get class of the
+     * enum type declaring an enum constant.
+     *
       * @return true if and only if this class was declared as an enum 
in the
       *     source code
       * @since 1.5
+     * @jls 8.9.1 Enum Constants
      public boolean isEnum() {
          // An enum must both directly extend java.lang.Enum and have

More information about the core-libs-dev mailing list