倩与倩寻
2018-08-30 20:27
Moveable moveable = (Moveable)Proxy.newProxyInstance(cls.getClassLoader(),cls.getInterfaces(),handler);
System.out.println("产生动态代理实例的类名称 = [" + moveable.getClass().getName() + "]");Proxy类的
newProxyInstance
方法,再反射回去 找类的名字,不应该是Proxy吗?为什么是$Proxy0?
@CallerSensitive
public static Object newProxyInstance(ClassLoader loader,
Class<?>[] interfaces,
InvocationHandler h)
throws IllegalArgumentException{
...
return cons.newInstance(new Object[]{h});
}
这个方法返回的是一个对象,一个动态生成的代理类的对象,moveable.getClass().getName()得到的是动态生成的这个代理类的名字。模式的秘密---代理模式
54903 学习 · 134 问题
相似问题