package cn.itcast.day3;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
public class ProxyTest {
/**
@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Class clazzProxy=Proxy.getProxyClass(Collection.class.getClassLoader(), Collection.class);
String ProxyName=clazzProxy.getName();
/*Constructor[] constructors=clazzProxy.getConstructors();
for(Constructor constructor: constructors){
StringBuilder sBuilder=new StringBuilder();
sBuilder.append(ProxyName);
sBuilder.append('(');
Class[] pTypes=constructor.getParameterTypes();
for(Class pType: pTypes){
sBuilder.append(pType.getName()+",");
}
sBuilder.deleteCharAt(sBuilder.length()-1);
sBuilder.append(')');
System.out.println(sBuilder);
}*/
Method[] methods=clazzProxy.getMethods();
for(Method method: methods){
StringBuilder sBuilder=new StringBuilder();
sBuilder.append(method.getName());
sBuilder.append('(');
Class[] pTypes=method.getParameterTypes();
for(Class pType: pTypes){
sBuilder.append(pType.getName()+",");
}
if(pTypes.length!=0)
sBuilder.deleteCharAt(sBuilder.length()-1);
sBuilder.append(')');
System.out.println(sBuilder);
}
}
}
代理:JVM自动生成.class文件 等到.class的构造函数和成员方法
最新推荐文章于 2022-03-21 13:24:08 发布