方法覆盖和功能接口编译错误
Method overriding and Functional Interface complie error
我在使用 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
会导致错误;删除其中任何一个,代码就会编译。这是正确的行为吗?如果是这样,我如何can/should重构?
更新
这似乎产生了类似的错误:
@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个抽象方法,超过了@FunctionalInterface
.
施加的 1 的限制
这里没有什么神秘的。
从 Eclipse Mars 切换到 Oxygen 解决了这个问题。谢谢。
这是 Eclipse bug 453552,自 4.6M1 起已修复,因此任何 Neon 版本(当前为 Neon.1,即将推出 Neon.2)都包含该修复程序。
我在使用 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
会导致错误;删除其中任何一个,代码就会编译。这是正确的行为吗?如果是这样,我如何can/should重构?
更新
这似乎产生了类似的错误:
@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个抽象方法,超过了@FunctionalInterface
.
这里没有什么神秘的。
从 Eclipse Mars 切换到 Oxygen 解决了这个问题。谢谢。
这是 Eclipse bug 453552,自 4.6M1 起已修复,因此任何 Neon 版本(当前为 Neon.1,即将推出 Neon.2)都包含该修复程序。