views:

51

answers:

2

I have the following code:

private static final Set<String> allowedParameters;
static {
    Set<String> tmpSet = new HashSet();
    tmpSet.add("aaa");
    allowedParameters = Collections.unmodifiableSet(tmpSet);
}

And it cause:

Note: mygame/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

And when I recompile with the suggested option I see a pointer (^) pointing at "new" in front of HashSet();.

Does anybody know what is going on here?

+6  A: 

Yes, you're creating a new HashSet without stating what class it should contain, and then asserting that it contains strings. Change it to

 Set<String> tmpSet = new HashSet<String>();
JacobM
+2  A: 

these messages occur when you are using classes that support the new J2SE 1.5 feature - generics. You get them when you do not explicitly specify the type of the collection's content.

For example:

List l = new ArrayList();
list.add("String");
list.add(55);

If you want to have a collection of a single data type you can get rid of the messages by:

List<String> l = new ArrayList<String>();
list.add("String");

If you need to put multiple data types into once collection, you do:

List<Object> l = new ArrayList<Object>();
list.add("String");
list.add(55);

If you add the -Xlint:unchecked parameter to the compiler, you get the specific details about the problem.

for more details refer here : http://forums.sun.com/thread.jspa?threadID=584311

GK