Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

operators are not found if the parameters are not exactly the same as the arguments #49

Copy link
Copy link
@wietlol

Description

@wietlol
Issue body actions

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)

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.