类 Proxy中的方法:
newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h)
的第二个参数,在JDK中这样描述:interfaces - the list of interfaces for the proxy class to implement1、我如果 我有这么个接口:
public interface Subject {
public void requst();
}
2、有这么个类去实现这个接口:
public class RealSubject implements Subject {
public void requst() {
System.out.println("From real subject!");
}可以这样去 获得:
realSubject.getClass().getInterfaces()
而不能这样去获得:
Subject.class.getInterfaces() ?
我想问的是,好像没有听说过“用接口”去取得 Class 对象的想法过哦···
newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h)
的第二个参数,在JDK中这样描述:interfaces - the list of interfaces for the proxy class to implement1、我如果 我有这么个接口:
public interface Subject {
public void requst();
}
2、有这么个类去实现这个接口:
public class RealSubject implements Subject {
public void requst() {
System.out.println("From real subject!");
}可以这样去 获得:
realSubject.getClass().getInterfaces()
而不能这样去获得:
Subject.class.getInterfaces() ?
我想问的是,好像没有听说过“用接口”去取得 Class 对象的想法过哦···
*
* @return an array of interfaces implemented by this class.
*/
public native Class<?>[] getInterfaces();
这个方法返回的是该类实现的接口。 Subject是个接口,它没有实现任何接口,所以Subject.class.getInterfaces()返回size为0的数组。