Here you can find the source of getConstructors(Class cl)
Parameter | Description |
---|---|
cl | a class |
public static String getConstructors(Class cl)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.*; public class Main { /**/* w w w . java 2 s . c o m*/ * Prints all constructors of a class * * @param cl a class */ public static String getConstructors(Class cl) { String clName = cl.getName(); Class superClass = cl.getSuperclass(); String superClassName = ""; if (superClass != null) superClassName = superClass.getName(); StringBuilder constr = new StringBuilder( "\n\nConstructors for class: " + clName + " inherits " + superClassName + " \n"); Constructor[] constructors = cl.getDeclaredConstructors(); for (Constructor c : constructors) { String name = c.getName(); constr.append(" " + Modifier.toString(c.getModifiers())); constr.append(" " + name + "("); // print parameter types Class[] paramTypes = c.getParameterTypes(); for (int j = 0; j < paramTypes.length; j++) { if (j > 0) constr.append(", "); constr.append(paramTypes[j].getName()); } constr.append("); \n"); } return constr.toString(); } }