I want to ask if there is a way to treat same type of warnings differently. I mean you can choose how to treat every warning (like warning unused, error unchecked cast and so on), but can I tell the compiler to treat one unused warning as error and ignore another (somehow specify where to treat as error and where to ignore it)?
Asked
Active
Viewed 43 times
1
-
`@SuppressWarnings(“unused“)` and code style settings – Joop Eggen Jan 13 '17 at 14:17
2 Answers
1
You can use the @SuppressWarnings annotation. The warnings that can be suppressed are listed here: What is the list of valid @SuppressWarnings warning names in Java?
0
You have two options:
- Explicitly suppress warnings by adding a directive in each file
- Instruct the compiler to suppress warnings for all files
The @SuppressWarnings
annotation allows you to suppress a warning, and can be applied to most Java blocks. Most IDEs will create a @SuppressWarnings
annotation for you, as one of the hint options when a warning occurs.
man javac
describes the -Xlint
command line parameter.
There's a long list of options, for example if you want to disable the "raw types" warning:
javac -Xlint:-rawtypes ...
Most IDEs and build systems provide ways of passing parameters to javac
-- check the documentation for yours.

slim
- 40,215
- 13
- 94
- 127