What do @SuppressWarnings("deprecation") and ("unused") mean in Java?
The @SuppressWarnings
annotation disables certain compiler warnings. In this case, the warning about deprecated code ("deprecation"
) and unused local variables or unused private methods ("unused"
). This article explains the possible values.
One more thing: you can not only add them inline, but also annotate methods. For example
@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.