2016-08-11 7 views
2

で抽象メソッドをオーバーライドするhiger注文機能を使用して、私は次のような定義があります抽象クラスでJava

protected abstract A expectedA(B b); 

    protected Function<A, B> createExpectedA(Long foo) { 
    return a -> { ... return b}} 

そして、私はそうのようcreateExpectedAからリターン機能を抽象関数をオーバーライドします:

@Override 
    protected Function<A, B> expectedA = createExpectedA(fee); 

は、しかし、これは私に次のエラーを与える:

The annotation @Override is disallowed for this location

Java8で私が望むことを、私はどうすればできますか?

+0

あなたが@Overrideを使用するには、「通常」の方法を知っていますか? –

+0

'protected abstract A expectedA(B b)'の戻り値の型が 'protected Function expectedA = createExpectedA(fee)'の戻り値の型と一致しません。それを修正することから始めます。 – bradimus

答えて

3

注釈Overrideは、フィールド上にないメソッドで使用されるため、このエラーが発生します。

Indicates that a method declaration is intended to override a method declaration in a supertype. If a method is annotated with this annotation type compilers are required to generate an error message unless at least one of the following conditions hold:

  • The method does override or implement a method declared in a supertype.
  • The method has a signature that is override-equivalent to that of any public method declared in Object.

何をしたい、このようなもののように見える:リマインダーとして、ここでのJavadocがある

@Override 
protected A expectedA(B b) { 
    return createExpectedA(fee).apply(b); 
}