What do @SuppressWarnings(“deprecation”) and (“unused”) mean in Java?

前端 未结 4 524
终归单人心
终归单人心 2020-12-13 12:20

What do these lines in my Java or Android project mean?

@SuppressWarnings(\"deprecation\")
@SuppressWarnings(\"unused\")
4条回答
  •  遥遥无期
    2020-12-13 12:23

    One more thing: you can not only add them inline, but also annotate methods. F.ex.

    @Override
    @SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
    

    Yet, it is recommended to use the smallest scope possible

    As a matter of style, programmers should always use this annotation on the most deeply nested element where it is effective. If you want to suppress a warning in a particular method, you should annotate that method rather than its class.

提交回复
热议问题