java.lang.IllegalArgumentException: object is not an instance of declaring class
时间: 2023-10-16 12:29:55 浏览: 110
This exception is thrown when a method is invoked on an object that is not an instance of the declaring class.
For example, suppose you have a class called `MyClass` with a method called `myMethod`:
```
public class MyClass {
public void myMethod() {
// do something
}
}
```
If you try to call `myMethod` on an object that is not an instance of `MyClass`, you will get the `IllegalArgumentException`.
```
Object obj = new Object();
MyClass mc = new MyClass();
mc.myMethod(); // this is valid
obj.myMethod(); // throws IllegalArgumentException
```
In the above code, `obj` is an instance of `Object`, not `MyClass`, so calling `myMethod` on it will result in an `IllegalArgumentException`.
阅读全文