Class Modifier
java.lang.Object
java.lang.reflect.Modifier
The Modifier class provides
static methods andconstants to decode class and member access modifiers. The sets ofmodifiers are represented as integers with distinct bit positionsrepresenting different modifiers. The values for the constantsrepresenting 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 arerepresented in this class, only those modifiers thatalsohave a corresponding JVMaccess flag areincluded. In particular the
defaultmethod modifier (JLS9.4.3) and thesealedandnon-sealedclass(JLS8.1.1.2) and interface (JLS9.1.1.4) modifiersarenot represented in this class. - Since:
- 1.1
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intTheintvalue representing theabstractmodifier.static final intTheintvalue representing thefinalmodifier.static final intTheintvalue representing theinterfacemodifier.static final intTheintvalue representing thenativemodifier.static final intTheintvalue representing theprivatemodifier.static final intTheintvalue representing theprotectedmodifier.static final intTheintvalue representing thepublicmodifier.static final intTheintvalue representing thestaticmodifier.static final intTheintvalue representing thestrictfpmodifier.static final intTheintvalue representing thesynchronizedmodifier.static final intTheintvalue representing thetransientmodifier.static final intTheintvalue representing thevolatilemodifier.Method Summary
Modifier and TypeMethodDescriptionstatic intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to a class.static intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to a constructor.static intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to a field.static intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to an interface.static booleanisAbstract(int mod) Returntrueif the integer argument includes theabstractmodifier,falseotherwise.static booleanisFinal(int mod) Returntrueif the integer argument includes thefinalmodifier,falseotherwise.static booleanisInterface(int mod) Returntrueif the integer argument includes theinterfacemodifier,falseotherwise.static booleanisNative(int mod) Returntrueif the integer argument includes thenativemodifier,falseotherwise.static booleanisPrivate(int mod) Returntrueif the integer argument includes theprivatemodifier,falseotherwise.static booleanisProtected(int mod) Returntrueif the integer argument includes theprotectedmodifier,falseotherwise.static booleanisPublic(int mod) Returntrueif the integer argument includes thepublicmodifier,falseotherwise.static booleanisStatic(int mod) Returntrueif the integer argument includes thestaticmodifier,falseotherwise.static booleanisStrict(int mod) Returntrueif the integer argument includes thestrictfpmodifier,falseotherwise.static booleanisSynchronized(int mod) Returntrueif the integer argument includes thesynchronizedmodifier,falseotherwise.static booleanisTransient(int mod) Returntrueif the integer argument includes thetransientmodifier,falseotherwise.static booleanisVolatile(int mod) Returntrueif the integer argument includes thevolatilemodifier,falseotherwise.static intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to a method.static intReturn anintvalue OR-ing together the source languagemodifiers that can be applied to a parameter.staticStringtoString(int mod) Return a string describing the access modifier flags inthe specified modifier.
Field Details
PUBLIC
public static final int PUBLICTheintvalue representing thepublicmodifier.PRIVATE
public static final int PRIVATETheintvalue representing theprivatemodifier.PROTECTED
public static final int PROTECTEDTheintvalue representing theprotectedmodifier.STATIC
public static final int STATICTheintvalue representing thestaticmodifier.FINAL
public static final int FINALTheintvalue representing thefinalmodifier.SYNCHRONIZED
public static final int SYNCHRONIZEDTheintvalue representing thesynchronizedmodifier.VOLATILE
public static final int VOLATILETheintvalue representing thevolatilemodifier.TRANSIENT
public static final int TRANSIENTTheintvalue representing thetransientmodifier.NATIVE
public static final int NATIVETheintvalue representing thenativemodifier.INTERFACE
public static final int INTERFACETheintvalue representing theinterfacemodifier.ABSTRACT
public static final int ABSTRACTTheintvalue representing theabstractmodifier.STRICT
public static final int STRICTTheintvalue representing thestrictfpmodifier.
Method Details
isPublic
public static boolean isPublic(int mod) Returntrueif the integer argument includes thepublicmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thepublicmodifier;falseotherwise.
isPrivate
public static boolean isPrivate(int mod) Returntrueif the integer argument includes theprivatemodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes theprivatemodifier;falseotherwise.
isProtected
public static boolean isProtected(int mod) Returntrueif the integer argument includes theprotectedmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes theprotectedmodifier;falseotherwise.
isStatic
public static boolean isStatic(int mod) Returntrueif the integer argument includes thestaticmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thestaticmodifier;falseotherwise.
isFinal
public static boolean isFinal(int mod) Returntrueif the integer argument includes thefinalmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thefinalmodifier;falseotherwise.
isSynchronized
public static boolean isSynchronized(int mod) Returntrueif the integer argument includes thesynchronizedmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thesynchronizedmodifier;falseotherwise.
isVolatile
public static boolean isVolatile(int mod) Returntrueif the integer argument includes thevolatilemodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thevolatilemodifier;falseotherwise.
isTransient
public static boolean isTransient(int mod) Returntrueif the integer argument includes thetransientmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thetransientmodifier;falseotherwise.
isNative
public static boolean isNative(int mod) Returntrueif the integer argument includes thenativemodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thenativemodifier;falseotherwise.
isInterface
public static boolean isInterface(int mod) Returntrueif the integer argument includes theinterfacemodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes theinterfacemodifier;falseotherwise.
isAbstract
public static boolean isAbstract(int mod) Returntrueif the integer argument includes theabstractmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes theabstractmodifier;falseotherwise.
isStrict
public static boolean isStrict(int mod) Returntrueif the integer argument includes thestrictfpmodifier,falseotherwise.- Parameters:
mod- a set of modifiers- Returns:
trueifmodincludes thestrictfpmodifier;falseotherwise.
toString
Return a string describing the access modifier flags inthe specified modifier. For example:
The modifier names are returned in an order consistent with thesuggested 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 final synchronized strictfp
Thepublic protected private abstract static final transientvolatile synchronized native strictfpinterfaceinterfacemodifier discussed in this class isnot a true modifier in the Java language and it appears afterall other modifiers listed by this method. This method mayreturn a string of modifiers that are not valid modifiers of aJava entity; in other words, no checking is done on thepossible validity of the combination of modifiers representedby the input.Note that to perform such checking for a known kind of entity,such as a constructor or method, first AND the argument oftoStringwith the appropriate mask from a method likeconstructorModifiers()ormethodModifiers().- API Note:
- To make a high-fidelity representation of the Java sourcemodifiers of a class or member, source-level modifiers that donot have a constant in this class should be includedand appear in an order consistent with the full recommendedordering for that kind of declaration as given inTheJava Language Specification. For example, for amethod the "
default" modifier is ordered immediatelybefore "static" (JLS9.4). For aclass object, the "sealed" or"non-sealed"modifier isordered immediately after "final" for a class (JLS8.1.1) and immediately after "static" for aninterface (JLS9.1.1). - Parameters:
mod- a set of modifiers- Returns:
- a string representation of the set of modifiersrepresented by
mod
classModifiers
public static int classModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to a class.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to a class. - SeeJava Language Specification:
- 8.1.1 Class Modifiers
- Since:
- 1.7
- See Also:
interfaceModifiers
public static int interfaceModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to an interface.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to an interface. - SeeJava Language Specification:
- 9.1.1 Interface Modifiers
- Since:
- 1.7
- See Also:
constructorModifiers
public static int constructorModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to a constructor.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to a constructor. - SeeJava Language Specification:
- 8.8.3 Constructor Modifiers
- Since:
- 1.7
- See Also:
methodModifiers
public static int methodModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to a method.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to a method. - SeeJava Language Specification:
- 8.4.3 Method Modifiers
- Since:
- 1.7
- See Also:
fieldModifiers
public static int fieldModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to a field.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to a field. - SeeJava Language Specification:
- 8.3.1 Field Modifiers
- Since:
- 1.7
- See Also:
parameterModifiers
public static int parameterModifiers()Return anintvalue OR-ing together the source languagemodifiers that can be applied to a parameter.- Returns:
- an
intvalue OR-ing together the source languagemodifiers that can be applied to a parameter. - SeeJava Language Specification:
- 8.4.1 Formal Parameters
- Since:
- 1.8
- See Also: