Modifier.PUBLIC has the following syntax.
public static final int PUBLIC
In the following code shows how to use Modifier.PUBLIC field.
/*from w w w . j a v a 2 s .co m*/ import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; public class Main { public static void main(String... args) throws Exception { Class<?> c = Class.forName("java.lang.String"); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { int searchMod = Modifier.PUBLIC; int mods = accessModifiers(ctor.getModifiers()); if (searchMod == mods) { System.out.println(ctor); } } } private static int accessModifiers(int m) { return m & Modifier.PUBLIC; } }
The code above generates the following result.