Android - Suppresswarnings用法

當(dāng)Android編譯java代碼的時(shí)候,經(jīng)常會(huì)遇到一些warning,有一些是自己寫得不規(guī)范,可以根據(jù)建議來修改,而有一些是你覺得必要的,不能修改的,比如說某些方法未被使用的warning。

Paste_Image.png

出現(xiàn)這種情況,你可以使用@Suppresswarnings來解決:

Paste_Image.png

而@Suppresswarnings("")里面的字符串""有多種選擇,以下是常見的:

name using
all to suppress all warnings (將方法塊里面所有的warning都取消)
cast to suppress warnings relative to cast operations
dep-ann to suppress warnings relative to deprecated annotation (取消對(duì)已棄用的注釋的警告)
deprecation to suppress warnings relative to deprecation( 使用了不贊成使用的類或方法時(shí)的警告)
fallthrough to suppress warnings relative to missing breaks in switch statements(當(dāng) Switch 程序塊直接通往下一種情況而沒有 Break 時(shí)的警告。)
finally to suppress warnings relative to finally block that don’t return(任何 finally 子句不能正常完成時(shí)的警告)
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) (取消對(duì)switch里面缺少case條目的警告)
null to suppress warnings relative to null analysis(取消對(duì)null分析的警告)
nls to suppress warnings relative to non-nls string literals (取消對(duì) non-nls字符串的警告)
path 在類路徑、源文件路徑等中有不存在的路徑時(shí)的警告。
rawtypes to suppress warnings relative to un-specific types when using generics on class params (當(dāng)在類參數(shù)中使用非特定的泛型時(shí),取消警告)
restriction to suppress warnings relative to usage of discouraged or forbidden references (取消使用不鼓勵(lì)或禁止的引用的警告)
serial to suppress warnings relative to missing serialVersionUID field for a serializable class(當(dāng)在可序列化的類上缺少 serialVersionUID 定義時(shí)的警告。)
static-access to suppress warnings relative to incorrect static access(取消不正常的靜態(tài)訪問的警告)
synthetic-access to suppress warnings relative to unoptimized access from inner classes
unchecked to suppress warnings relative to unchecked operations(執(zhí)行了未檢查的轉(zhuǎn)換時(shí)的警告,例如當(dāng)使用集合時(shí)沒有用泛型 (Generics) 來指定集合保存的類型。)
unqualified-field-access to suppress warnings relative to field access unqualified
unused to suppress warnings relative to unused code (將未使用的方法的warning取消)
WeakerAccess 禁止“Access can be private”的警告
最后編輯于
?著作權(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)容