java-oo
java-oo copied to clipboard
operators are not found if the parameters are not exactly the same as the arguments
Consider the following scenario:
public class Test
{
public void foo()
{
A a = new A();
B b = new B();
Base c = a & b; // << "Operator '&' cannot be applied to 'A', 'B'"
c = a.and(b);
c = a + b; // << "Operator '+' cannot be applied to 'A', 'B'"
c = a.add(b);
}
}
class A implements Base { }
class B implements Base { }
interface Base
{
default Base and(Base other) { return this; }
default Base add(Base other) { return this; }
}
As you might imagine, the functional syntax works fine as "a" implements Base so it has the and/add methods and "b" implements Base so it is a valid parameter. But the operator syntax cannot recognize them as valid operators.
If I change the parameters from Base to B, it works fine. Or if I change the variable "B b" to "Base b", it also works fine. The same also happens if Base is a class.
However, I have 16 classes that all have to be able to use the "and" operator on each other. And that would result in 16*15 methods with all duplicate code that could very well be in one interface.
I am using IntelliJ Ultimate version 2017.2 with the Java-oo plugin 0.6. (Javac compiler)
This issue is the same as the issue #29. I can confirm that this exists only in IntelliJ.