當Android編譯java代碼的時候,經常會遇到一些warning,有一些是自己寫得不規范,可以根據建議來修改,而有一些是你覺得必要的,不能修改的,比如說某些方法未被使用的warning。
Paste_Image.png
出現這種情況,你可以使用@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 (取消對已棄用的注釋的警告) |
deprecation | to suppress warnings relative to deprecation( 使用了不贊成使用的類或方法時的警告) |
fallthrough | to suppress warnings relative to missing breaks in switch statements(當 Switch 程序塊直接通往下一種情況而沒有 Break 時的警告。) |
finally | to suppress warnings relative to finally block that don’t return(任何 finally 子句不能正常完成時的警告) |
hiding | to suppress warnings relative to locals that hide variable(取消對隱藏變量的警告) |
incomplete-switch | to suppress warnings relative to missing entries in a switch statement (enum case) (取消對switch里面缺少case條目的警告) |
null | to suppress warnings relative to null analysis(取消對null分析的警告) |
nls | to suppress warnings relative to non-nls string literals (取消對 non-nls字符串的警告) |
path | 在類路徑、源文件路徑等中有不存在的路徑時的警告。 |
rawtypes | to suppress warnings relative to un-specific types when using generics on class params (當在類參數中使用非特定的泛型時,取消警告) |
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(當在可序列化的類上缺少 serialVersionUID 定義時的警告。) |
static-access | to suppress warnings relative to incorrect static access(取消不正常的靜態訪問的警告) |
synthetic-access | to suppress warnings relative to unoptimized access from inner classes |
unchecked | to suppress warnings relative to unchecked operations(執行了未檢查的轉換時的警告,例如當使用集合時沒有用泛型 (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”的警告 |