Java知识点总结(注解-内置注解)
生活随笔
收集整理的這篇文章主要介紹了
Java知识点总结(注解-内置注解)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Java知識點總結(注解-內置注解)
@(Java知識點總結)[Java, 注解]
@Override
- 定義在java.lang.Override 中,此注釋只適用于修飾方法,表示一個方法聲明打算重寫父類的另一個方法聲明。
源碼
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 { }@Deprecated
- 定義在java.lang.Deprecated中,遺棄、廢棄,不建議使用。此注釋可用于修飾方法、屬性、類,表示不鼓勵程序員使用這樣的元素,通常是因為它很危險或存在更好的選擇。
源碼
import java.lang.annotation.*; import static java.lang.annotation.ElementType.*;/*** A program element annotated @Deprecated is one that programmers* are discouraged from using, typically because it is dangerous,* or because a better alternative exists. Compilers warn when a* deprecated program element is used or overridden in non-deprecated code.** @author Neal Gafter* @since 1.5* @jls 9.6.3.6 @Deprecated*/ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) public @interface Deprecated { }@SuppressWarings
- 定義在java.lang.SuppressWarnings中,用來抑制編譯時的警告信息。
- 與前兩個注釋有所不同, 你需要添加一個參數才能正確使用 ,這些參數值是已經定義好了的,我們選擇性的使用就好了,參數如下:
| deprecation | 使用了過時的類或方法的警告 |
| unchecked | 執行了未檢查的轉換時的警告,如使用集合時未指定泛型 |
| fallthrough | 當在switch語句使用時發生case穿透 |
| path | 在類路徑、源文件路徑等中有不存在路徑的警告 |
| serial | 當在可序列化的類上缺少serialVersionUID定義時的警告 |
| finally | 任何finally子句不能完成時的警告 |
| all | 關于以上所有情況的警告 |
源碼
package java.lang;import java.lang.annotation.*; import static java.lang.annotation.ElementType.*;/*** Indicates that the named compiler warnings should be suppressed in the* annotated element (and in all program elements contained in the annotated* element). Note that the set of warnings suppressed in a given element is* a superset of the warnings suppressed in all containing elements. For* example, if you annotate a class to suppress one warning and annotate a* method to suppress another, both warnings will be suppressed in the method.** <p>As a matter of style, programmers should always use this annotation* on the most deeply nested element where it is effective. If you want to* suppress a warning in a particular method, you should annotate that* method rather than its class.** @author Josh Bloch* @since 1.5* @jls 4.8 Raw Types* @jls 4.12.2 Variables of Reference Type* @jls 5.1.9 Unchecked Conversion* @jls 5.5.2 Checked Casts and Unchecked Casts* @jls 9.6.3.5 @SuppressWarnings*/ @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}) @Retention(RetentionPolicy.SOURCE) public @interface SuppressWarnings {/*** The set of warnings that are to be suppressed by the compiler in the* annotated element. Duplicate names are permitted. The second and* successive occurrences of a name are ignored. The presence of* unrecognized warning names is <i>not</i> an error: Compilers must* ignore any warning names they do not recognize. They are, however,* free to emit a warning if an annotation contains an unrecognized* warning name.** <p> The string {@code "unchecked"} is used to suppress* unchecked warnings. Compiler vendors should document the* additional warning names they support in conjunction with this* annotation type. They are encouraged to cooperate to ensure* that the same names work across multiple compilers.* @return the set of warnings to be suppressed*/String[] value(); }總結
以上是生活随笔為你收集整理的Java知识点总结(注解-内置注解)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 20180915牛客A 你好诶加币
- 下一篇: POJ 1182 食物链(并查集+偏移向