Modifier

The Modifier class provides static methods and constants to decode class and member access modifiers.

ReturnFieldSummary
static intABSTRACTThe int value representing the abstract modifier.
static intFINALThe int value representing the final modifier.
static intINTERFACEThe int value representing the interface modifier.
static intNATIVEThe int value representing the native modifier.
static intPRIVATEThe int value representing the private modifier.
static intPROTECTEDThe int value representing the protected modifier.
static intPUBLICThe int value representing the public modifier.
static intSTATICThe int value representing the static modifier.
static intSTRICTThe int value representing the strictfp modifier.
static intSYNCHRONIZEDThe int value representing the synchronized modifier.
static intTRANSIENTThe int value representing the transient modifier.
static intVOLATILEThe int value representing the volatile modifier.

ReturnMethodSummary
static booleanisAbstract(int mod)Is abstract modifier.
static booleanisFinal(int mod)Is final modifier.
static booleanisInterface(int mod)Is interface modifier.
static booleanisNative(int mod)Is native modifier.
static booleanisPrivate(int mod)Is private modifier.
static booleanisProtected(int mod)Is protected modifier.
static booleanisPublic(int mod)Is public modifier.
static booleanisStatic(int mod)Is static modifier.
static booleanisStrict(int mod)Is strictfp modifier.
static booleanisSynchronized(int mod)Is synchronized modifier.
static booleanisTransient(int mod)Is transient modifier.
static booleanisVolatile(int mod)Is volatile modifier.
static StringtoString(int mod)Convert modifier int flag to string.

Return true if the integer argument includes the public modifier, false otherwise


import java.lang.reflect.Modifier;

public class Main {
  public static void main(String[] args) throws Exception {
    getClassModifier(String.class);
  }

  private static void getClassModifier(Class clazz) {
    int modifier = clazz.getModifiers();

    if (Modifier.isPublic(modifier)) {
      System.out.println(clazz.getName() + " class modifier is public");
    }
  }
}

The output:


java.lang.String class modifier is public
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.