Java Reflection - Java Constructor.getName()








Syntax

Constructor.getName() has the following syntax.

public String getName()

Example

In the following code shows how to use Constructor.getName() method.

import java.lang.reflect.Constructor;
import java.util.ArrayList;
/*from   w  w w.j  a  v  a  2 s .  c  om*/
public class Main {
  public static void main(String[] argv) throws Exception {
      Constructor[] constructors = ArrayList.class.getDeclaredConstructors();

      for (int i = 0; i < constructors.length; i++) {
        Constructor c = constructors[i];
        System.out.println(c.getName());
      }
    }
  
}

The code above generates the following result.