You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
Consider the following scenario:
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)
The text was updated successfully, but these errors were encountered: