If this exception is encountered:
Check whether the object instance is correct:
invoker is the instance of the object that testMethod is defined in.
java.lang.IllegalArgumentException: object is not an instance of declaring class
Check whether the object instance is correct:
Method method = invoker.getClass().getMethod("testMethod");
method.invoke(invoker); // must be invoker, don't set "this"
invoker is the instance of the object that testMethod is defined in.
本文介绍了一种常见的Java异常:java.lang.IllegalArgumentException,并提供了解决方案。当尝试调用对象的方法时,如果该对象不是定义此方法的类的实例,则会抛出此异常。文章通过示例代码展示了如何确保正确地调用方法。
8万+

被折叠的 条评论
为什么被折叠?



