@Overrideの1.5と1.6以降の違いについて
@Override注記は、ソースコードに作用する注記であり、注記のメソッドが親タイプのメソッドを書き換えたことを示すために使用されますが、この注記は1.5と1.6以降では異なります.1.5では、クラスを継承するときに親クラスのメソッドを書き換える場合にのみ使用できますが、1つのインタフェースのメソッドを実装する場合は、1.6から親インタフェースを実装するメソッドが使用できません.ただし,@Overrideソース文書では,1.6はこの変化を説明せず,1.7になってから説明した.
以下は1.5と1.6のソースコードです.
次は1.7のソースです.このメソッドは、親タイプで宣言されたメソッド を書き換えまたは実装する.メソッドの署名は、Objectクラスで宣言された共通メソッドと等価(override-equivalent)の を書き換える.
書き換え等価の意味についてはhttp://stackoverflow.com/questions/16207386/what-is-override-equivalence-and-how-is-it-related-to-override
2つの単語の変化に気づくことができます.
Indicates that a method declaration is intended to override a method declaration in a superclass.
Indicates that a method declaration is intended to override a method declaration in a supertype.
それは1.5でsuperclass、1.7でsupertypeです.1つは親で、1つは親タイプです.なぜ1.6の文書がこの変化に対して修正されていないのか、実質的にインタフェースを実現する方法をサポートして@Overrideを使用できるのかは不明ですが、文書の更新が遅れているのかもしれません.
作者:mhmyqn发表于2015/8/29 15:53:38原文链接
読書:94コメント:0コメントの表示
以下は1.5と1.6のソースコードです.
package java.lang;
import java.lang.annotation.*;
/**
* Indicates that a method declaration is intended to override a
* method declaration in a superclass. If a method is annotated with
* this annotation type but does not override a superclass method,
* compilers are required to generate an error message.
*
* @author Joshua Bloch
* @since 1.5
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}
は、メソッド宣言がスーパークラスのメソッド宣言を書き換えるつもりであることを意味する.メソッドがこの注釈タイプを使用して注釈を行い、スーパークラスメソッドを書き換えていない場合、コンパイラはエラーメッセージを生成します.次は1.7のソースです.
package java.lang;
import java.lang.annotation.*;
/**
* 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:
*
* <ul><li>
* The method does override or implement a method declared in a
* supertype.
* </li><li>
* The method has a signature that is override-equivalent to that of
* any public method declared in {@linkplain Object}.
* </li></ul>
*
* @author Peter von der Ahé
* @author Joshua Bloch
* @jls 9.6.1.4 Override
* @since 1.5
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}
は、親タイプのメソッド宣言を書き換えるメソッド宣言を表す.メソッドがこの注釈タイプを使用して注釈を行う場合、コンパイラは次の2つの条件のいずれかを満たさない限り、エラーメッセージを生成する必要があります.書き換え等価の意味についてはhttp://stackoverflow.com/questions/16207386/what-is-override-equivalence-and-how-is-it-related-to-override
2つの単語の変化に気づくことができます.
Indicates that a method declaration is intended to override a method declaration in a superclass.
Indicates that a method declaration is intended to override a method declaration in a supertype.
それは1.5でsuperclass、1.7でsupertypeです.1つは親で、1つは親タイプです.なぜ1.6の文書がこの変化に対して修正されていないのか、実質的にインタフェースを実現する方法をサポートして@Overrideを使用できるのかは不明ですが、文書の更新が遅れているのかもしれません.
作者:mhmyqn发表于2015/8/29 15:53:38原文链接
読書:94コメント:0コメントの表示