方法覆盖和功能接口编译错误

问题描述:

我已经复制了使用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。

+0

你所看到的具体错误是什么? –

+0

提供的代码编译没有任何错误。 – gr7

+0

@ marcus.ramsden **无效的“@FunctionalInterface”注释; Refined 不是一个功能接口**编译器错误指出'Refined'和'Another'接口不是功能接口。我无法使用lambda表达式,'@FunctionalInterface'注释会产生编译错误。 – bizness86

这是Eclipse bug 453552,它固定为4.6M1,所以任何Neon发行版(目前Neon.1,即将推出Neon.2)都包含修复程序。

Functioner有一个抽象方法funnelledThenFanned(),并Another添加newMethod(),使得抽象方法,这超过了由@FunctionalInterface施加的限制。

这里没有神秘感。

+1

'Another'还定义了'funnelledThenFanned()',它将'newMethod()'作为单一抽象方法。 – bizness86

从Eclipse Mars切换到Oxygen解决了这个问题。谢谢。