@SuppressWarnings注解

@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ò)的代碼的警告)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容