3

I read about the -Xlint:unchecked in the Oracle Java tutorial link. And I would like to setup my IDE to inform me about unsafe code. But I faced some troubles trying to accomplish so. But I managed to get a warning message in my Terminal using command:

javac GenericsMain.java Box.java -Xlint:unchecked

I got such message

GenericsMain.java:19: warning: [unchecked] unchecked call to addItem(T)
as a member of the raw type Box
rawBox.addItem(8);
^
where T is a type-variable:
T extends Object declared in class Box
GenericsMain.java:23: warning:
[unchecked] unchecked call to addItem(T) as a member of the raw type Box
rawBox.addItem(8);
^
where T is a type-variable:
T extends Object declared in class Box
2 warnings

How can I provide this in my IDE? Thank you.

1 Answers1

9

Settings (Ctrl+Alt+S / ,) > Build, Execution, Deployment > Compiler > Java Compiler > "Additional command line parameters"

This is a per project setting.

screen shot of IntelliJ > Settings/Preferences > Build, Execution, Deployment > Compiler > Java Compiler panel

To set for new future projects, set the same under File > Other Settings > Default Settings

screen shot of IntelliJ > File > Other Settings > Default Settings > Build, Execution, Deployment > Compiler > Java Compiler >

More details at: https://www.jetbrains.com/help/idea/java-compiler.html

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Javaru
  • 30,412
  • 11
  • 93
  • 70
  • 2
    Tor clarify… The key is to understand that IntelliJ merges project-specific settings with app-wide settings (or "Preferences" on macOS). Look for faint text at top of settings panel noting “For current project”. I find this merging to be confusing, but *c’est la vie*. – Basil Bourque Sep 13 '17 at 22:25
  • This answer is only correct if you are using IntelliJ "native" projects, for the Ant and Maven answer see https://stackoverflow.com/a/8215793/3610458 – SensorSmith Mar 12 '20 at 20:56