-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using properties in classes that extend a class implementing the same interface can lead to a Reference is ambiguous
error
#643
Comments
By chance I am working on a set of properties changes that should fix this, will be ready in a week or so. For the interim you can qualify the ambiguous reference with public void foo(){
Object superObject = this.object;
} |
Adding Test2 test2 = ....;
Object obj = test2.object; // error
Object obj = test2.this.object; // error, not valid to write this I'm eagerly awaiting your solution! |
Yes, I think the changes I have fix this. I whipped up a test reflecting yours here plus random other bits. public void testDoubleImplements()
{
MyClass2 myClass2 = new MyClass2();
Object object = myClass2.object;
assertNull(object);
myClass2.object = "hello";
assertEquals(myClass2.object, "hello");
MyClass myClass = myClass2;
myClass.object = "hi";
assertEquals(myClass.object, "hi");
}
public interface TestIntf {
Object getObject();
}
public static class MyClass implements TestIntf {
@override @var Object object;
void whatever()
{
object = "hey";
}
}
public static class MyClass2 extends MyClass implements TestIntf {
public void foo(){
object = "hi"; // should not be ambiguous ref
Object value = object; // should not be ambiguous ref
MyClass2 mc2 = new MyClass2();
mc2.object = value;
}
} Please let me know if there are other cases you see that fail. Thanks! |
Fix available with release 2024.1.43 |
Thanks, this seems to have fixed the problem. However, IntelliJ is still marking it as an error (probably something that should be fixed in the IntelliJ plugin?) |
Describe the bug
Using properties in classes that extend a class implementing the same interface can lead to a
Reference is ambiguous
error. Consider the following example:In this example, referencing
object
inTest2
results in an ambiguity. While only one actual object exists, both the fieldTest.object
and the methodTestIntf.getObject()
are seen as possible references.In this simple case, you could remove
implements TestIntf
from theTest2
class to resolve the conflict. However, in more complex scenarios, such as multiple inheritance or interface combinations, this approach may not be feasible.To resolve the issue, the getter method
getObject()
can be used directly instead of the property reference. However, IntelliJ flags this as a warning:Use property 'object' here
.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: