日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java知识点总结(注解-内置注解)

發(fā)布時(shí)間:2025/3/15 java 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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è)方法聲明。
public class Demo01 {@Overridepublic String toString() {return "";}}

源碼

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&eacute;* @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)或存在更好的選擇。
public class Demo01 {@Deprecatedpublic static void test1(){}public static void main(String[] args) {test1();} }

源碼

import java.lang.annotation.*; import static java.lang.annotation.ElementType.*;/*** A program element annotated &#64;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ù)如下:
參數(shù)說(shuō)明
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)于以上所有情況的警告
@SuppressWarnings("unchecked") @SuppressWarnings(value={"unchecked","deprecation"}) import java.util.ArrayList; import java.util.List;public class Demo01 {@SuppressWarnings("all")public static void test2(){List list = new ArrayList();}

源碼

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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。