1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package com.fanshe;
import java.lang.reflect.Constructor; import java.lang.reflect.Modifier;
public class ReflectTest11 { public static void main(String[] args) throws Exception { StringBuilder s = new StringBuilder(); Class vipClass = Class.forName("java.lang.String"); s.append(Modifier.toString(vipClass.getModifiers())); s.append(" class "); s.append(vipClass.getSimpleName()); s.append("{\n");
Constructor[] constructors = vipClass.getDeclaredConstructors(); for(Constructor constructor : constructors) { s.append("\t"); s.append(Modifier.toString(constructor.getModifiers())); s.append(" "); s.append(vipClass.getSimpleName()); s.append("("); Class[] parameterTypes = constructor.getParameterTypes(); for(Class paraterType : parameterTypes) { s.append(paraterType.getSimpleName()); s.append(","); } if(parameterTypes.length > 0) s.deleteCharAt(s.length() - 1);
s.append("){}\n"); }
s.append("}"); System.out.println(s); } }
|