Java Reflection - Java Constructor.toString()








Syntax

Constructor.toString() has the following syntax.

public String toString()

Example

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

//w ww .  j  ava 2 s  .c o m
import java.lang.reflect.Constructor;
import java.util.ArrayList;

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.toString());
      }
    }
  
}

The code above generates the following result.