Class Modifier

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

public classModifierextendsObject
The Modifier class providesstatic methods and constants to decode class and member access modifiers. The sets of modifiers are represented as integers with distinct bit positions representing different modifiers. The values for the constants representing the modifiers are taken from the tables in sections4.1,4.4,4.5, and4.7 ofThe Java Virtual Machine Specification.
API Note:
Not all modifiers that are syntactic Java language modifiers are represented in this class, only those modifiers thatalso have a corresponding JVMaccess flag are included. In particular thedefault method modifier (JLS9.4.3) and thesealed andnon-sealed class (JLS8.1.1.2) and interface (JLS9.1.1.4) modifiers arenot represented in this class.
Since:
1.1
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Theint value representing theabstract modifier.
    static final int
    Theint value representing thefinal modifier.
    static final int
    Theint value representing theinterface modifier.
    static final int
    Theint value representing thenative modifier.
    static final int
    Theint value representing theprivate modifier.
    static final int
    Theint value representing theprotected modifier.
    static final int
    Theint value representing thepublic modifier.
    static final int
    Theint value representing thestatic modifier.
    static final int
    Theint value representing thestrictfp modifier.
    static final int
    Theint value representing thesynchronized modifier.
    static final int
    Theint value representing thetransient modifier.
    static final int
    Theint value representing thevolatile modifier.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to a class.
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to a constructor.
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to a field.
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to an interface.
    static boolean
    isAbstract(int mod)
    Returntrue if the integer argument includes theabstract modifier,false otherwise.
    static boolean
    isFinal(int mod)
    Returntrue if the integer argument includes thefinal modifier,false otherwise.
    static boolean
    isInterface(int mod)
    Returntrue if the integer argument includes theinterface modifier,false otherwise.
    static boolean
    isNative(int mod)
    Returntrue if the integer argument includes thenative modifier,false otherwise.
    static boolean
    isPrivate(int mod)
    Returntrue if the integer argument includes theprivate modifier,false otherwise.
    static boolean
    isProtected(int mod)
    Returntrue if the integer argument includes theprotected modifier,false otherwise.
    static boolean
    isPublic(int mod)
    Returntrue if the integer argument includes thepublic modifier,false otherwise.
    static boolean
    isStatic(int mod)
    Returntrue if the integer argument includes thestatic modifier,false otherwise.
    static boolean
    isStrict(int mod)
    Returntrue if the integer argument includes thestrictfp modifier,false otherwise.
    static boolean
    isSynchronized(int mod)
    Returntrue if the integer argument includes thesynchronized modifier,false otherwise.
    static boolean
    isTransient(int mod)
    Returntrue if the integer argument includes thetransient modifier,false otherwise.
    static boolean
    isVolatile(int mod)
    Returntrue if the integer argument includes thevolatile modifier,false otherwise.
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to a method.
    static int
    Return anint value OR-ing together the source language modifiers that can be applied to a parameter.
    staticString
    toString(int mod)
    Return a string describing the access modifier flags in the specified modifier.
  • Field Details

  • Method Details

    • isPublic

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

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

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

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

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

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

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

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

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

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

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

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

      public static String toString(int mod)
      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 ofThe Java Language Specification. The full modifier ordering used by this method is:
      public protected private abstract static final transient volatile synchronized native strictfp interface
      Theinterface 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. Note that to perform such checking for a known kind of entity, such as a constructor or method, first AND the argument oftoString with the appropriate mask from a method likeconstructorModifiers() ormethodModifiers().
      API Note:
      To make a high-fidelity representation of the Java source modifiers of a class or member, source-level modifiers that donot have a constant in this class should be included and appear in an order consistent with the full recommended ordering for that kind of declaration as given inThe Java Language Specification. For example, for amethod the "default" modifier is ordered immediately before "static" (JLS9.4). For aclass object, the "sealed" or"non-sealed" modifier is ordered immediately after "final" for a class (JLS8.1.1) and immediately after "static" for an interface (JLS9.1.1).
      Parameters:
      mod - a set of modifiers
      Returns:
      a string representation of the set of modifiers represented bymod
    • classModifiers

      public static int classModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to a class.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to a class.
      SeeJava Language Specification:
      8.1.1 Class Modifiers
      Since:
      1.7
    • interfaceModifiers

      public static int interfaceModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to an interface.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to an interface.
      SeeJava Language Specification:
      9.1.1 Interface Modifiers
      Since:
      1.7
    • constructorModifiers

      public static int constructorModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to a constructor.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to a constructor.
      SeeJava Language Specification:
      8.8.3 Constructor Modifiers
      Since:
      1.7
    • methodModifiers

      public static int methodModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to a method.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to a method.
      SeeJava Language Specification:
      8.4.3 Method Modifiers
      Since:
      1.7
    • fieldModifiers

      public static int fieldModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to a field.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to a field.
      SeeJava Language Specification:
      8.3.1 Field Modifiers
      Since:
      1.7
    • parameterModifiers

      public static int parameterModifiers()
      Return anint value OR-ing together the source language modifiers that can be applied to a parameter.
      Returns:
      anint value OR-ing together the source language modifiers that can be applied to a parameter.
      SeeJava Language Specification:
      8.4.1 Formal Parameters
      Since:
      1.8