2016-12-16 50 views
0

我已經複製了使用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

回答

0

這是Eclipse bug 453552,它固定爲4.6M1,所以任何Neon發行版(目前Neon.1,即將推出Neon.2)都包含修復程序。

1

Functioner有一個抽象方法funnelledThenFanned(),並Another添加newMethod(),使得抽象方法,這超過了由@FunctionalInterface施加的限制。

這裏沒有神祕感。

+1

'Another'還定義了'funnelledThenFanned()',它將'newMethod()'作爲單一抽象方法。 – bizness86

0

從Eclipse Mars切換到Oxygen解決了這個問題。謝謝。