反射,问大家个很简单的问题!
类 Proxy中的方法:
newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h)
的第二个参数,在JDK中这样描述:
interfaces - the list of interfaces for the proxy class to implement
1、我如果 我有这么个接口:
public interface Subject {
public void requst();
}
2、有这么个类去实现这个接口:
public class RealSubject implements Subject {
public void requst() {
System.out.println("From real subject!");
}
}
我的目的只想获得最上面的 “interfaces”:
请问为什么可以这样去 获得:
realSubject.getClass().getInterfaces()
而不能这样去获得:
Subject.class.getInterfaces() ?
[最优解释]
它是生成的代理类实现了那些接口
可以试试通过InvocationHandler invoke方法的第一个参数去getInterfaces
[其他解释]
楼主可以将realSubject.getClass()和Subject.class分别打印出来,看看这两个对象分别是什么
[其他解释]