< prev index next >

src/java.base/share/classes/java/lang/reflect/Modifier.java

Print this page
@@ -23,16 +23,19 @@
   * questions.
   */
  
  package java.lang.reflect;
  
+ import jdk.internal.javac.PreviewFeature;
+ 
  import java.util.StringJoiner;
  
  /**
   * The Modifier class provides {@code static} methods and
-  * constants to decode class and member access modifiers.  The sets of
-  * modifiers are represented as integers with distinct bit positions
+  * constants to decode class and member access modifiers.
+  * The {@link AccessFlag} class should be used instead of this class.
+  * The sets of modifiers are represented as integers with non-distinct bit positions
   * representing different modifiers.  The values for the constants
   * representing the modifiers are taken from the tables in sections
   * {@jvms 4.1}, {@jvms 4.4}, {@jvms 4.5}, and {@jvms 4.7} of
   * <cite>The Java Virtual Machine Specification</cite>.
   *

@@ -121,18 +124,39 @@
  
      /**
       * Return {@code true} if the integer argument includes the
       * {@code synchronized} modifier, {@code false} otherwise.
       *
+      * @apiNote {@code isSynchronized} should only be called with the modifiers
+      * of a {@linkplain Method#getModifiers() method}.
+      *
       * @param   mod a set of modifiers
       * @return {@code true} if {@code mod} includes the
       * {@code synchronized} modifier; {@code false} otherwise.
       */
      public static boolean isSynchronized(int mod) {
          return (mod & SYNCHRONIZED) != 0;
      }
  
+     /**
+      * Return {@code true} if the integer argument includes the
+      * {@code identity} modifier, {@code false} otherwise.
+      *
+      * @apiNote {@code isIdentity} should only be called with the modifiers
+      * of a {@linkplain Class#getModifiers() class}.
+      *
+      * @param   mod a set of modifiers
+      * @return {@code true} if {@code mod} includes the
+      * {@code identity} modifier; {@code false} otherwise.
+      *
+      * @since Valhalla
+      */
+     @PreviewFeature(feature = PreviewFeature.Feature.VALUE_OBJECTS, reflective=true)
+     public static boolean isIdentity(int mod) {
+         return (mod & IDENTITY) != 0;
+     }
+ 
      /**
       * Return {@code true} if the integer argument includes the
       * {@code volatile} modifier, {@code false} otherwise.
       *
       * @param   mod a set of modifiers

@@ -317,10 +341,19 @@
       * modifier.
       * @see AccessFlag#SYNCHRONIZED
       */
      public static final int SYNCHRONIZED     = 0x00000020;
  
+     /**
+      * The {@code int} value representing the {@code ACC_IDENTITY}
+      * modifier.
+      *
+      * @since Valhalla
+      */
+     @PreviewFeature(feature = PreviewFeature.Feature.VALUE_OBJECTS, reflective=true)
+     public static final int IDENTITY         = 0x00000020;
+ 
      /**
       * The {@code int} value representing the {@code volatile}
       * modifier.
       * @see AccessFlag#VOLATILE
       */

@@ -355,11 +388,11 @@
      public static final int ABSTRACT         = 0x00000400;
  
      /**
       * The {@code int} value representing the {@code strictfp}
       * modifier.
-      * @see AccessFlag#STRICT
+      * @see AccessFlag#STRICT and AccessFlag#STRICT_FIELD
       */
      public static final int STRICT           = 0x00000800;
  
      // Bits not (yet) exposed in the public API either because they
      // have different meanings for fields and methods and there is no

@@ -394,11 +427,11 @@
       * @jls 8.1.1 Class Modifiers
       */
      private static final int CLASS_MODIFIERS =
          Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
          Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
-         Modifier.STRICT;
+         Modifier.IDENTITY       | Modifier.STRICT;
  
      /**
       * The Java source modifiers that can be applied to an interface.
       * @jls 9.1.1 Interface Modifiers
       */

@@ -428,11 +461,11 @@
       * @jls 8.3.1 Field Modifiers
       */
      private static final int FIELD_MODIFIERS =
          Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
          Modifier.STATIC         | Modifier.FINAL        | Modifier.TRANSIENT |
-         Modifier.VOLATILE;
+         Modifier.VOLATILE       | Modifier.STRICT;
  
      /**
       * The Java source modifiers that can be applied to a method or constructor parameter.
       * @jls 8.4.1 Formal Parameters
       */
< prev index next >