zoukankan      html  css  js  c++  java
  • JAVA中@SuppressWarnings注解的作用

    eclipse中开发JAVA代码时,经常会出现编译告警符号,影响代码可读性,也影响调试的断点符号正常显示,可以使用@SuppressWarnings注解来抑制这些告警符号的再现。
    1.抑制单个类型的告警:

    @SuppressWarnings("unused")
    public void test1() {
        String s = "test";
    }

    2.抑制多个类型的告警:

    @SuppressWarnings({"unused", "rawtypes"})
    public void test2() {
        List list = new ArrayList();
    }

    3.抑制所有类型的告警:

    @SuppressWarnings("all")
    public void test3() {
        String s = "test";
    }

    以下是@SuppressWarnings注解中各个可选值含义描述:

    all 抑制所有警告 to suppress all warnings
    boxing 抑制装箱、拆箱操作时候的警告 to suppress warnings relative to boxing/unboxing operations
    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 抑制在switch中缺失break的警告 to suppress warnings relative to missing breaks in switch statements
    finally 抑制finally模块没有返回的警告 to suppress warnings relative to finally block that don’t return
    hiding 抑制隐藏的本地变量相对应的警告 to suppress warnings relative to locals that hide variable
    incomplete-switch 忽略没有完整的switch语句 to suppress warnings relative to missing entries in a switch statement (enum case)
    nls 忽略非nls格式的字符 to suppress warnings relative to non-nls string literals
    null 忽略对null的操作 to suppress warnings relative to null analysis
    rawtypes 使用generics时忽略没有指定相应的类型 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 忽略在serializable类中没有声明serialVersionUID变量 to suppress warnings relative to missing serialVersionUID field for a serializable class
    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
    unqualified-field-access 抑制没有权限访问的域的警告 to suppress warnings relative to field access unqualified
    unused 抑制没被使用过的代码的警告 to suppress warnings relative to unused code
  • 相关阅读:
    SynchronousQueue、LinkedBlockingQueue、ArrayBlockingQueue性能测试
    JDK源码分析—— ArrayBlockingQueue 和 LinkedBlockingQueue
    ArrayBlockingQueue和LinkedBlockingQueue的区别
    Net处理html页面元素工具类(HtmlAgilityPack.dll)的使用
    WebView混合开发
    对付"反盗链"
    通过代码来操作SQLite的示例
    System.Data.SQLite未能加载文件或程序集
    Using SQLXML Bulk Load in the .NET Environment
    Asynchronous Programming Using Delegates使用委托进行异步编程
  • 原文地址:https://www.cnblogs.com/atai/p/6936566.html
Copyright © 2011-2022 走看看