Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ says "Warning: java: foo/bar/Baz.java uses unchecked or unsafe operations", but it doesn't say in which line it is referring to

I am getting this warning:

ScreenShot

When I click on the image, it just opens the associated Editor, but it doesn't say the line number where the warning is raised. I don't want to add @SuppressWarning("unchecked") on the whole class...

Any workaround/fix?

like image 669
Luigi R. Viggiano Avatar asked Jan 09 '13 15:01

Luigi R. Viggiano


People also ask

How do you fix unchecked or unsafe operations in Java?

How to resolve warning message: uses unchecked or unsafe operations. You can resolve this warning message by using generics with Collections. In our example, we should use ArrayList<String> rather than ArrayList() . When you will compile above code, you won't get warning message anymore.

How do I recompile a Java class in Intellij?

Open the needed file in the editor and from the main menu, select Build | Recompile 'class name' ( Ctrl+Shift+F9 ). Alternatively, in the Project tool window, right-click the class you need and from the context menu, select Recompile 'class name'.


2 Answers

To compile with -Xlint:unchecked in IntelliJ IDEA:

  • Go to Settings dialog (Ctrl+Alt+S or +, )
  • Select Compiler > Java Compiler
  • Add following into the field Additional command line parameters:

    -Xlint:unchecked

  • Run your compile again

like image 150
devmake Avatar answered Sep 22 '22 06:09

devmake


IntelliJ IDEA 15

A faster solution:

  • Press Ctrl + Shift + A
  • Type "Additional com" and press Enter:

    Additional command line parameters

  • Type -Xlint:unchecked > OK

    Xlint unchecked

  • Press Ctrl + Shift + F9 to recompile (or go to Build > Compile ... )

    • you can select a class / module from the project tree to specify what you want to be recompiled
  • You will see the line and the column where the problem appeared

    E.g.: Warning:(5,27) java: unchecked ...

like image 28
ROMANIA_engineer Avatar answered Sep 22 '22 06:09

ROMANIA_engineer