方法覆盖和功能界面补充错误



我在使用Java 8 @FunctionalInterface(Eclipse)时复制了我遇到的错误。以下没有编译;Refined产生错误:

@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扩展了所有FunctionReceiverGiver均导致错误;删除其中的任何一个,然后编译代码。这是正确的行为吗?如果是这样,我应该/应该如何重构?

update

这似乎会产生类似的错误:

@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() {
        ...
    }
}

另外,我会注意到,如果没有@FunctionalInterface,所有内容都会编译;接口实例不能以lambda表示。

Functioner具有一个抽象方法funnelledThenFanned(),并且Another添加了newMethod(),使 2 抽象方法超过 1 1 的限制@FunctionalInterface

这里没有神秘。

这是Eclipse Bug 453552,截至4.6M1,因此任何霓虹灯释放(当前Neon.1,noreon.2)都包含修复程序。

从eclipse火星切换到氧气解决了这个问题。谢谢。

相关内容

最新更新