登录
  • 欢迎访问 Sharezer Blog

Android - Suppresswarnings用法

Android sharezer 1089次浏览 已收录 0个评论

当 Android 编译 java 代码的时候,经常会遇到一些 warning,有一些是自己写得不规范,可以根据建议来修改,而有一些是你觉得必要的,不能修改的,比如说某些方法未被使用的 warning。

Android - Suppresswarnings用法

出现这种情况,你可以使用 @Suppresswarnings 来解决:

Android - Suppresswarnings用法

而 @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” 的警告

Sharezer , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Android - Suppresswarnings用法
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址