1

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)?

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
Evgeni
  • 13
  • 2

2 Answers2

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?

Community
  • 1
  • 1
Jeroen
  • 158
  • 8
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