Class Modifier

java.lang.Object
java.lang.reflect.Modifier

public final class Modifier extends Object
Provides static methods and constants to decode classfile access and property flags with corresponding Java language modifiers.

Modifier interpretation is context-sensitive: for example, the isSynchronized check is only meaningful for method access flags, representing the synchronized modifier on methods. A true return on a field access flags does not indicate that field has the synchronized modifier.

API Note:
The mappings from classfile access flags to Java language modifiers have diverged during the evolution of the Java SE Platform. Many access flags and Java language modifiers are not represented in this class; the mappings represented in this class are not sufficient to reconstruct Java langugage modifiers from access flags, and vice versa.
Since:
1.1
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The int value representing the abstract modifier.
    static final int
    The int value representing the final modifier.
    static final int
    The int value representing the interface modifier.
    static final int
    The int value representing the native modifier.
    static final int
    The int value representing the private modifier.
    static final int
    The int value representing the protected modifier.
    static final int
    The int value representing the public modifier.
    static final int
    The int value representing the static modifier.
    static final int
    The int value representing the strictfp modifier.
    static final int
    The int value representing the synchronized modifier.
    static final int
    The int value representing the transient modifier.
    static final int
    The int value representing the volatile modifier.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static boolean
    isAbstract(int mod)
    Return true if the integer argument includes the abstract modifier, false otherwise.
    static boolean
    isFinal(int mod)
    Return true if the integer argument includes the final modifier, false otherwise.
    static boolean
    isInterface(int mod)
    Return true if the integer argument includes the interface modifier, false otherwise.
    static boolean
    isNative(int mod)
    Return true if the integer argument includes the native modifier, false otherwise.
    static boolean
    isPrivate(int mod)
    Return true if the integer argument includes the private modifier, false otherwise.
    static boolean
    isProtected(int mod)
    Return true if the integer argument includes the protected modifier, false otherwise.
    static boolean
    isPublic(int mod)
    Return true if the integer argument includes the public modifier, false otherwise.
    static boolean
    isStatic(int mod)
    Return true if the integer argument includes the static modifier, false otherwise.
    static boolean
    isStrict(int mod)
    Return true if the integer argument includes the strictfp modifier, false otherwise.
    static boolean
    isSynchronized(int mod)
    Return true if the integer argument includes the synchronized modifier, false otherwise.
    static boolean
    isTransient(int mod)
    Return true if the integer argument includes the transient modifier, false otherwise.
    static boolean
    isVolatile(int mod)
    Return true if the integer argument includes the volatile modifier, false otherwise.
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static int
    Deprecated.
    This method was originally created to support the now-deprecated Modifier::toString(int) method.
    static String
    toString(int mod)
    Deprecated.
    Modifier interpretation is context-sensitive; this API may report an incomplete or incorrect list of Java language modifiers.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Creates and returns a copy of this object.
    boolean
    Indicates whether some other object is "equal to" this one.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Finalization is deprecated and subject to removal in a future release.
    final Class<?>
    Returns the runtime class of this Object.
    int
    Returns a hash code value for this object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
    final void
    wait(long timeoutMillis)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
    final void
    wait(long timeoutMillis, int nanos)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  • Field Details

  • Method Details

    • isPublic

      public static boolean isPublic(int mod)
      Return true if the integer argument includes the public modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the public modifier; false otherwise.
    • isPrivate

      public static boolean isPrivate(int mod)
      Return true if the integer argument includes the private modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the private modifier; false otherwise.
    • isProtected

      public static boolean isProtected(int mod)
      Return true if the integer argument includes the protected modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the protected modifier; false otherwise.
    • isStatic

      public static boolean isStatic(int mod)
      Return true if the integer argument includes the static modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the static modifier; false otherwise.
    • isFinal

      public static boolean isFinal(int mod)
      Return true if the integer argument includes the final modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the final modifier; false otherwise.
    • isSynchronized

      public static boolean isSynchronized(int mod)
      Return true if the integer argument includes the synchronized modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the synchronized modifier; false otherwise.
    • isVolatile

      public static boolean isVolatile(int mod)
      Return true if the integer argument includes the volatile modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the volatile modifier; false otherwise.
    • isTransient

      public static boolean isTransient(int mod)
      Return true if the integer argument includes the transient modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the transient modifier; false otherwise.
    • isNative

      public static boolean isNative(int mod)
      Return true if the integer argument includes the native modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the native modifier; false otherwise.
    • isInterface

      public static boolean isInterface(int mod)
      Return true if the integer argument includes the interface modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the interface modifier; false otherwise.
    • isAbstract

      public static boolean isAbstract(int mod)
      Return true if the integer argument includes the abstract modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the abstract modifier; false otherwise.
    • isStrict

      public static boolean isStrict(int mod)
      Return true if the integer argument includes the strictfp modifier, false otherwise.
      Parameters:
      mod - a set of modifiers
      Returns:
      true if mod includes the strictfp modifier; false otherwise.
    • toString

      @Deprecated(since="27") public static String toString(int mod)
      Deprecated.
      Modifier interpretation is context-sensitive; this API may report an incomplete or incorrect list of Java language modifiers. The mappings from class file access flags to Java language modifiers have diverged during the evolution of the Java SE Platform.

      Use AccessFlag to examine access flags; toGenericString methods on reflective objects print Java language modifiers.

      Return a string describing the access modifier flags in the specified modifier. For example:
         public final synchronized strictfp
      
      The modifier names are returned in an order consistent with the suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of The Java Language Specification. The full modifier ordering used by this method is:
      public protected private abstract static final transient volatile synchronized native strictfp interface
      The interface modifier discussed in this class is not a true modifier in the Java language and it appears after all other modifiers listed by this method. This method may return a string of modifiers that are not valid modifiers of a Java entity; in other words, no checking is done on the possible validity of the combination of modifiers represented by the input. This method also omits all access flags without a corresponding source modifier.
      Parameters:
      mod - a set of modifiers
      Returns:
      a string representation of the set of modifiers represented by mod
    • classModifiers

      @Deprecated(since="27") public static int classModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to a class.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to a class.
      See Java Language Specification:
      8.1.1 Class Modifiers
      Since:
      1.7
      See Also:
    • interfaceModifiers

      @Deprecated(since="27") public static int interfaceModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to an interface.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to an interface.
      See Java Language Specification:
      9.1.1 Interface Modifiers
      Since:
      1.7
      See Also:
    • constructorModifiers

      @Deprecated(since="27") public static int constructorModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to a constructor.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to a constructor.
      See Java Language Specification:
      8.8.3 Constructor Modifiers
      Since:
      1.7
      See Also:
    • methodModifiers

      @Deprecated(since="27") public static int methodModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to a method.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to a method.
      See Java Language Specification:
      8.4.3 Method Modifiers
      Since:
      1.7
      See Also:
    • fieldModifiers

      @Deprecated(since="27") public static int fieldModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to a field.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to a field.
      See Java Language Specification:
      8.3.1 Field Modifiers
      Since:
      1.7
      See Also:
    • parameterModifiers

      @Deprecated(since="27") public static int parameterModifiers()
      Deprecated.
      This method was originally created to support the now-deprecated Modifier::toString(int) method. Use AccessFlag.Location to inspect structure-specific access modifier properties.
      Return an int value OR-ing together the source language modifiers that can be applied to a parameter.
      Returns:
      an int value OR-ing together the source language modifiers that can be applied to a parameter.
      See Java Language Specification:
      8.4.1 Formal Parameters
      Since:
      1.8
      See Also: