Java知识点总结(注解-内置注解)
生活随笔
收集整理的這篇文章主要介紹了
Java知识点总结(注解-内置注解)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Java知識(shí)點(diǎn)總結(jié)(注解-內(nèi)置注解)
@(Java知識(shí)點(diǎn)總結(jié))[Java, 注解]
@Override
- 定義在java.lang.Override 中,此注釋只適用于修飾方法,表示一個(gè)方法聲明打算重寫(xiě)父類的另一個(gè)方法聲明。
源碼
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中,遺棄、廢棄,不建議使用。此注釋可用于修飾方法、屬性、類,表示不鼓勵(lì)程序員使用這樣的元素,通常是因?yàn)樗芪kU(xiǎn)或存在更好的選擇。
源碼
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中,用來(lái)抑制編譯時(shí)的警告信息。
- 與前兩個(gè)注釋有所不同, 你需要添加一個(gè)參數(shù)才能正確使用 ,這些參數(shù)值是已經(jīng)定義好了的,我們選擇性的使用就好了,參數(shù)如下:
| deprecation | 使用了過(guò)時(shí)的類或方法的警告 |
| unchecked | 執(zhí)行了未檢查的轉(zhuǎn)換時(shí)的警告,如使用集合時(shí)未指定泛型 |
| fallthrough | 當(dāng)在switch語(yǔ)句使用時(shí)發(fā)生case穿透 |
| path | 在類路徑、源文件路徑等中有不存在路徑的警告 |
| serial | 當(dāng)在可序列化的類上缺少serialVersionUID定義時(shí)的警告 |
| finally | 任何finally子句不能完成時(shí)的警告 |
| all | 關(guān)于以上所有情況的警告 |
源碼
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(); }總結(jié)
以上是生活随笔為你收集整理的Java知识点总结(注解-内置注解)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 20180915牛客A 你好诶加币
- 下一篇: Java:双向链表反转实现