Constructor: getName() : Constructor « java.lang.reflect « Java by API






Constructor: getName()

  
/*
java.util.ArrayList: 
java.util.ArrayList: Collection 
java.util.ArrayList: int 
 
 */
import java.lang.reflect.Constructor;

public class MainClass {

  public static void main(String[] args) {
    try {
      Class c = Class.forName("java.util.ArrayList");

      Constructor constructors[] = c.getConstructors();
      for (int i = 0; i < constructors.length; i++) {
        System.out.print(constructors[i].getName() + ": ");
        Class parameters[];
        parameters = constructors[i].getParameterTypes();
        for (int j = 0; j < parameters.length; j++) {
          String s = parameters[j].getName();
          s = s.substring(s.lastIndexOf(".") + 1, s.length());
          System.out.print(s + " ");
        }
        System.out.println("");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

           
         
    
  








Related examples in the same category

1.Constructor: getExceptionTypes()
2.Constructor: getParameterTypes()
3.Constructor: getModifiers()
4.Constructor: newInstance(Object... initargs)
5.Constructor: setAccessible(boolean flag)
6.Constructor: toGenericString()