manuelBetancurt
manuelBetancurt

Reputation: 16138

android HashMap warning

Im an Android noob, coming from objC,

I have a very stupid question (project working fine and logging expected results),

package com.orchard.hasho;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.util.Log;

public class Numa {

public static void main() {


    Map mMap = new HashMap(); //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());
    }


}
}

IN the last code i have a new HashMap, wich i load elements to,

But I get many warnings,

ie, Map mMap = new HashMap(); warning: add type arguments to "Map"

I have noticed that when i create the Map... the autocompletition gives me an option of Map<K, V>

but from my tutorial i dont see this <Key, Value> ? ??? syntax's when creating the Hashmap or populating it?

so what are this warnings, why the autocompetition gives me the option Map<K, V>, and how to fix the warnings?, thanks!

Upvotes: 0

Views: 1910

Answers (1)

jeet
jeet

Reputation: 29199

This is due to generalization feature in java 1.5, you can specify what type of object this map will contain, like if you want to use String as a key and value, please use following:

Map<String, String> mMap = new HashMap<String,String>();

Upvotes: 3

Related Questions