Method overriding and Functional Interface complie error

664 views Asked by At

I have replicated an error that I ran into while using Java 8 @FunctionalInterface (eclipse). The following does not compile; Refined produces the error:

@FunctionalInterface
interface Functioner<TFunnel, TFan> {
    Function<TFunnel, TFan> funnelledThenFanned();
}

@FunctionalInterface
interface Receiver<T, TFan>
extends Functioner<Supplier<? extends T>, TFan> {}

@FunctionalInterface
interface Giver<TFunnel, T>
extends Functioner<TFunnel, Supplier<T>> {}

@FunctionalInterface
interface Refined<T, R>
extends Function<T, R>, Receiver<T, Supplier<R>>, Giver<Supplier<? extends T>, R> {

    @Override
    public abstract R apply(T arg);

    @Override
    public default Function<Supplier<? extends T>, Supplier<R>> funnelledThenFanned() {
        ...
    }

}

Refined extending all of Function, Receiver and Giver causes the error; remove any one of these, and the code compiles. Is this the correct behavior? If so, how can/should I refactor?

UPDATE

This seems to produce a similar error:

@FunctionalInterface
interface Another<TFunnel, T>
extends Functioner<TFunnel, Supplier<T>>, Giver<TFunnel, T> {

    public abstract void newMethod();

    @Override
    public default Function<TFunnel, Supplier<T>> funnelledThenFanned() {
        ...
    }

}

Also, I'll note that without @FunctionalInterface everything compiles; interface instances just cannot be expressed as a lambda.

3

There are 3 answers

0
Stephan Herrmann On BEST ANSWER

This was Eclipse bug 453552, which was fixed as of 4.6M1, so any Neon release (currently Neon.1, soon Neon.2) contains the fix.

1
Bohemian On

Functioner has an abstract method funnelledThenFanned(), and Another adds newMethod(), making 2 abstract methods, which exceeds the limit of 1 imposed by @FunctionalInterface.

There is no mystery here.

0
bizness86 On

Switching from Eclipse Mars to Oxygen solved this problem. Thank you.