使用反射从超接口访问方法
Accessing Methods from a superInterface Using Reflection
我需要使用反射获取超级接口中定义的方法,因为反射不提供使用 currentClass.getDeclaredMethods() 的超级接口中的方法。
那么,是否可以获取超接口方法?
// I am using the Jms interface TopicConnection. But I am not able to access the "setClientID" method using reflection.
// That method is present in the super Interface "Connection". How do I get to that?
Class<?> superClass = topicConnectionClass.getSuperclass(); // this does not give the superInterface for the current Interface. and gives null since for interface superClass is null
checkMethod = superClass.getDeclaredMethod("setClientID", String.class);
使用 getInterfaces()
而不是 getSuperclass()
。
但是 - 必须有一个定义 setClientID
的 class,它必须是超级 class 之一,因此沿着超级 [= 迭代也是合适的=17=]关系。
我需要使用反射获取超级接口中定义的方法,因为反射不提供使用 currentClass.getDeclaredMethods() 的超级接口中的方法。 那么,是否可以获取超接口方法?
// I am using the Jms interface TopicConnection. But I am not able to access the "setClientID" method using reflection.
// That method is present in the super Interface "Connection". How do I get to that?
Class<?> superClass = topicConnectionClass.getSuperclass(); // this does not give the superInterface for the current Interface. and gives null since for interface superClass is null
checkMethod = superClass.getDeclaredMethod("setClientID", String.class);
使用 getInterfaces()
而不是 getSuperclass()
。
但是 - 必须有一个定义 setClientID
的 class,它必须是超级 class 之一,因此沿着超级 [= 迭代也是合适的=17=]关系。