Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

@SuppressWarnings("deprecation") @SuppressWarnings("unused") 
like image 368
Praveenkumar Avatar asked Sep 13 '11 07:09

Praveenkumar


People also ask

What is the use of @SuppressWarnings deprecation?

You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled. Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API.

What does @SuppressWarnings mean?

@SuppressWarnings instruct the compiler to ignore or suppress, specified compiler warning in annotated element and all program elements inside that element. For example, if a class is annotated to suppress a particular warning, then a warning generated in a method inside that class will also be separated.

What is the use of @SuppressWarnings unchecked in Java?

@SuppressWarnings("unchecked") is used when Java generics just don't let you do what you want to, and thus, you need to explicitly specify to the compiler that whatever you are doing is legal and can be executed at the time of execution.

What is @SuppressWarnings resource?

Adding the @SuppressWarnings({ "resource" }) should remove the warning for a potential resource leak. Adding a list for other ones, it's for Eclipse but they should be fairly similar for reference.


1 Answers

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.

like image 91
nfechner Avatar answered Sep 29 '22 11:09

nfechner