Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用反射从超级接口访问方法_Java_Reflection_Superclass - Fatal编程技术网

Java 使用反射从超级接口访问方法

Java 使用反射从超级接口访问方法,java,reflection,superclass,Java,Reflection,Superclass,我需要使用反射获取超级接口中定义的方法,因为反射不提供使用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 th

我需要使用反射获取超级接口中定义的方法,因为反射不提供使用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);
//我正在使用Jms接口TopicConnection。但是我无法使用反射访问“setClientID”方法。
//该方法出现在超级接口“连接”中。我该怎么做?
Class superClass=topicConnectionClass.getSuperclass();//这不会为当前接口提供超级接口。并给出null,因为for接口超类为null
checkMethod=superClass.getDeclaredMethod(“setClientID”,String.class);
使用
getInterfaces()
而不是
getSuperclass()


但是-必须有一个定义了
setClientID
的类,它必须是一个超类,因此沿着超类关系进行迭代也是合适的。

一个简短的示例可以帮助您实现这一点。我已经放置了小代码段