我正在尝试通过反射来调用方法。有问题的方法,比如说
public void someMethod(someInterface<someObject> arg1)
我无法在运行时访问someMethod
和someInterface
,并且必须通过
someclass.getMethod("someMethod", new Class[]{Class.forName("someInterface")})
.invoke(...)
但它失败了someInterface
的ClassNotFound异常。如何获取接口的Class
对象?
答案 0 :(得分:2)
从概念上讲,这对我来说是正确的。检查这些事情:
最后但并非最不重要; - )
答案 1 :(得分:1)
我相信你忘记了界面的包装。调用Class.forName()时必须使用完全限定的类名,即Class.forName('com.mycompany.MyClass')