Reputation: 16138
I am learning how to use HashMaps,
my test project is working, but i need to get rid of some warnings,
public static void main() {
Map <String, String>mMap = new HashMap<String, String>(); //crea nuevo HashMap
mMap.put("llave 1", "la llave uno"); //le mete cosas al hashMap
mMap.put("llave 2", "la llave dos");
mMap.put("llave 3", "la llave tres");
mMap.put("llave 4", "la llave cuatro");
Iterator iter = mMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry menEntry = (Map.Entry) iter.next();
Log.d("msg", "key:"+menEntry.getKey() +" value:"+menEntry.getValue());
} } }
so on
Iterator iter = mMap.entrySet().iterator();
i get the warning: multiple markers at this line
the autocompletition point to Iterator <E>
what is this, the cast?, Error?, what to put in there?
also same warning in:
Map.Entry menEntry = (Map.Entry) iter.next();
Thanks a lot!
Upvotes: 0
Views: 88
Reputation: 67286
Its because you are not defining the type at couple of place, that is
Iterator<Entry<String, String>> iter = mMap.entrySet().iterator();
and
Map.Entry<String, String> menEntry = (Map.Entry<String, String>) iter.next();
Edit
You can have a look at Generics in JAVA 1.5, here
is a small explanation for that.
Upvotes: 1
Reputation: 8612
This warnings show that you use classes, that will be better to parameterize. use Iterator <Entry<String, String>>
and Map.Entry<String, String>
Upvotes: 1