What is unhindered and insecure work here?

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 this causes:

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

And when I recompile with the proposed option, I see a pointer (^) pointing to the "new" before HashSet();.

Does anyone know what is going on here?

+5
source share
2 answers

Yes, you create a new HashSet without specifying which class it should contain, and then claim that it contains strings. Change it to

 Set<String> tmpSet = new HashSet<String>();
+9
source

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

For instance:

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

, :

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

, :

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

-Xlint: unchecked , .

. : http://forums.sun.com/thread.jspa?threadID=584311

+2

All Articles