views:

175

answers:

3

Hello,

What does it mean?

Note: Main.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

Any sugestions how to avoid that kind of errors?

+1  A: 

First, recompile with -Xlint:unchecked to see what the problem is. Then fix those problems. There are a number of potential high-level causes for unchecked warnings. One is that you didn't provide type parameters where you should have. There are some situations where they are unavoidable, and then you can suppress the specific warning, but these are the exception, and care must be taken that you aren't suppressing warnings that are really important.

So recompile with -Xlint:unchecked and post additional questions if you have trouble with any of the specific issues that are revealed.

Laurence Gonsalves
+3  A: 

That's the error you get when you use Collections without specifying a type. You probably have something like:

ArrayList myList = new ArrayList(); // or some other Collection class

If that's the case, you need to change that to specify what type of objects you want to store. For example:

ArrayList<String> myList = new ArrayList<String>();

Read up on Java Generics for more information.

This is my best guess without seeing your code and the full error message. There could be other causes for that message, this is just the problem that I've seen accompany that message before.

Bill the Lizard
A: 

What does it mean?

Java generics allow you to write something like this:

List<String> l = ...;
String s = l.get(0);  // note there is no explicit typecast.

But if the compiler tells you that your code has "unchecked or unsafe operations", it is saying that you have broken the rules for using generics safely, and your code may give runtime class cast exceptions at unexpected places; e.g. in the statement above where we left out the typecast.

There are a few things that will cause the compiler to complain about unchecked or unsafe operations, and each one requires a different remediation. Do what the compiler is telling you and run it with the -Xlint option.

Stephen C