Java Reflection - Java Modifier PRIVATE


Modifier.PRIVATE has the following syntax.

public static final int PRIVATE


In the following code shows how to use Modifier.PRIVATE field.

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
/*from   ww  w.  java2s  .  c  o m*/
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.PRIVATE;
      int mods = accessModifiers(ctor.getModifiers());
      if (searchMod == mods) {

  private static int accessModifiers(int m) {
    return m & Modifier.PRIVATE;