方法覆盖和功能接口编译错误
问题描述:
我已经复制了使用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
导致错误;删除其中的任何一个,然后编译代码。这是正确的行为?如果是这样,我该如何/应该重构?
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()
,使得抽象方法,这超过了由@FunctionalInterface
施加的限制。
这里没有神秘感。
+1
'Another'还定义了'funnelledThenFanned()',它将'newMethod()'作为单一抽象方法。 – bizness86
答
从Eclipse Mars切换到Oxygen解决了这个问题。谢谢。
你所看到的具体错误是什么? –
提供的代码编译没有任何错误。 – gr7
@ marcus.ramsden **无效的“@FunctionalInterface”注释; Refined不是一个功能接口**编译器错误指出'Refined'和'Another'接口不是功能接口。我无法使用lambda表达式,'@FunctionalInterface'注释会产生编译错误。 –
bizness86