How to declare a HashMap with different types?

I have a function declared as follows:

public synchronized void update(HashMap<String, Comparable> data)

the data contains strings and ints, but Comparable gives a warning

Comparable is a raw type. References to generic type Comparable<T> should be 
 parameterized

Since I did not find the warnings too often, the question is whether there is a correct way, I do not want to suppress the warning.

Thanks in advance! Marcus

+5
source share
2 answers

The compiler should like this:

public synchronized void update(HashMap<String, Comparable<Object>> data)

Object String, Integer. . Map, HashMap. -, Comparable, Map<String, Object>. , : .

"[...] ints [...]" - String Integer:

public synchronized void update(HashMap<String, Integer> data)
+3

, HashMap . Map? -, - Comparable. -, Comparable :

void update(Map<String, ? extends Comparable<?>> data)

HashMap<String, Integer>, TreeMap<String, String> SortedMap<String, Comparable<?>>.

+1

All Articles