我复制了在使用 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
扩展所有Function
,Receiver
并Giver
导致错误;删除其中任何一个,代码就会编译。这是正确的行为吗?如果是这样,我可以/应该如何重构?
更新
这似乎会产生类似的错误:
@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。