[code=java]import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
public class ProxyArray {
public static void main(String [] args){
Class proxyClazz= Proxy.getProxyClass(Collection.class.getClassLoader(), Collection.class);
System.out.println("------------开始打印构造函数列表----------------");
Constructor[] constructors =proxyClazz.getConstructors();
for(Constructor constructor:constructors){
String name = constructor.getName();
Class [] parameters=constructor.getParameterTypes();
StringBuilder sbuilder = new StringBuilder(name);
sbuilder.append("(");
for(Class parameter: parameters){
String clazzparameter=parameter.getName();
sbuilder.append(clazzparameter).append(',');
if (parameters.length!=0&¶meters!= null)
sbuilder.deleteCharAt(sbuilder.length()-1);
sbuilder.append(")");
System.out.println(sbuilder.toString());
}
}
System.out.println("------------开始打印方法列表----------------");
Method [] methods =proxyClazz.getMethods();
for(Method method:methods){
String name = method.getName();
StringBuilder sbuilder = new StringBuilder(name);
sbuilder.append("(");
Class [] parameters=method.getParameterTypes();
for(Class parameter: parameters){
String clazzparameter=parameter.getName();
sbuilder.append(clazzparameter).append(',');
if (parameters.length!=0&¶meters!= null)
sbuilder.deleteCharAt(sbuilder.length()-1);
sbuilder.append(")");
System.out.println(sbuilder.toString());
}
}
}
}[/code] |
|