Method “xxx” with signature “xxx” is not applicable on this object
Running into a problem with message “Method ‘xx’ with signature ‘xx’ is not applicable on this object”, still trying to figure it out.
Fixed.
In the Original code, there are three classes and Class A extends Class C, Class B extends Class C.
There are two methods in another class.
public void example1(C c)
{
example2(c);
}
private void example2(C c)
{
}
Because in the example1 method, the parameter c is a instance of A, when calls method example2, the method example2 with signature C is not applicable on this object.
The code after my fix:
public void example1(C c)
{
if(c instances A)
example2((A)c);
}else if (C instances B)
{
example3((B)c);
}
//Changed the parameter from C to A
private void example2(A a)
{
}
///added another method example3 with the parameter B
private void example3(B b)
{
}
来自我的小站 www.threes.cn
本文解决了一个关于方法签名不匹配的问题。原本的方法example1接受类型C的对象,但在调用example2时,参数实际上是类型A的实例,导致了方法不适用的错误。通过检查实例类型并显式转换,问题得以解决。
1569

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



