當(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”的警告 |