HashMap and put warnings because unchecked calls...

I'm writting an application that connects to some APIs, but when compiling, I get some warning messages:

warning: [unchecked] unchecked call to put(K, V) as a member of the raw type java.util.HashMap

Here is the code:

publicclass hashMapMgr{

HashMap hm;

public hashMapMgr(){

hm =new HashMap;

hm.clear();

}

publicvoid addKey(String key, String value)throws myException{

Object status;

if (key.length()==0 && value.length()==0){

throwsnew myException ("Error");

}

status = hm.put(key,value);

}

public HashMap getMap(){

return hm;

}

}

Why am I getting that warning message? Should I use a try..catch to remove the warning message? or should I extend or implement something?

Thanks

[1510 byte] By [RobertoZozayaa] at [2007-11-27 1:49:44]
# 1

The code you posted will not give you a warning but rather compile errors.

> ...

> Why am I getting that warning message? Should I use

> a try..catch to remove the warning message? or

> should I extend or implement something?

> ...

No. You should tell what type of object you're going to store in that HashMap (String's in your case).

So do it like this:

// ...

HashMap<String, String> hm;

public hashMapMgr() {

hm = new HashMap<String, String>();

}

// ...

You might also want to read up on Java's code conventions:

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Good luck.

prometheuzza at 2007-7-12 1:15:27 > top of Java-index,Core,Core APIs...
# 2
Thanks for the information..
RobertoZozayaa at 2007-7-12 1:15:27 > top of Java-index,Core,Core APIs...