@SuppressWarnings注解的作用
告訴編譯器忽略指定的警告攒庵,不在編譯完成后出現(xiàn)警告信息,這些警告信息顯示在代碼左側(cè)行列欄败晴,會(huì)擋住調(diào)試時(shí)的斷點(diǎn)浓冒。可注解類尖坤、字段稳懒、方法、參數(shù)糖驴、局部變量僚祷、構(gòu)造函數(shù)。
使用方式
-
@SuppressWarnings("")
如:@SuppressWarnings("unchecked")
贮缕,@SuppressWarnings("unchecked","rawtypes")
-
@SuppressWarnings({})
如:@SuppressWarnings({"unchecked","rawtypes"})
-
@SuppressWarnings(value={})
如:@SuppressWarnings(value={"unchecked","rawtypes"})
@SuppressWarnings("static-access")
public void fo(){
...
}
用途列表
根據(jù)使用需要辙谜,選擇表中的關(guān)鍵字。
關(guān)鍵字 | 用途 |
---|---|
all | to suppress all warnings (抑制所有警告) |
boxing | to suppress warnings relative to boxing/unboxing operations (抑制裝箱感昼、拆箱操作時(shí)候的警告) |
cast | to suppress warnings relative to cast operations (抑制映射相關(guān)的警告) |
dep-ann | to suppress warnings relative to deprecated annotation (抑制啟用注釋的警告) |
deprecation | to suppress warnings relative to deprecation (抑制過(guò)期方法警告) |
fallthrough | to suppress warnings relative to missing breaks in switch statements (抑制確在switch中缺失breaks的警告) |
finally | to suppress warnings relative to finally block that don’t return (抑制finally模塊沒(méi)有返回的警告) |
hiding | to suppress warnings relative to locals that hide variable (抑制相對(duì)于隱藏變量的局部變量的警告) |
incomplete-switch | to suppress warnings relative to missing entries in a switch statement (enum case) (忽略沒(méi)有完整的switch語(yǔ)句) |
nls | to suppress warnings relative to non-nls string literals ( 忽略非nls格式的字符) |
null | to suppress warnings relative to null analysis ( 忽略對(duì)null的操作) |
rawtypes | to suppress warnings relative to un-specific types when using generics on class params ( 使用generics時(shí)忽略沒(méi)有指定相應(yīng)的類型) |
restriction | to suppress warnings relative to usage of discouraged or forbidden references ( 抑制禁止使用勸阻或禁止引用的警告) |
serial | to suppress warnings relative to missing serialVersionUID field for a serializable class ( 忽略在serializable類中沒(méi)有聲明serialVersionUID變量) |
static-access | to suppress warnings relative to incorrect static access ( 抑制不正確的靜態(tài)訪問(wèn)方式警告) |
synthetic-access | to suppress warnings relative to unoptimized access from inner classes ( 抑制子類沒(méi)有按最優(yōu)方法訪問(wèn)內(nèi)部類的警告) |
unchecked | to suppress warnings relative to unchecked operations ( 抑制沒(méi)有進(jìn)行類型檢查操作的警告) |
unqualified-field-access | to suppress warnings relative to field access unqualifiedv ( 抑制沒(méi)有權(quán)限訪問(wèn)的域的警告) |
unused | to suppress warnings relative to unused code ( 抑制沒(méi)被使用過(guò)的代碼的警告) |