I have a function, declared like this:
public synchronized void update(HashMap<String, Comparable> data)
data contains strings and ints, but the Comparable gives a warning
Comparable is a raw type. References to generic type Comparable<T> should be
parameterized
As I’m not overly found of warnings, question is, is there a correct way, I don’t want to suppress the warning.
Thank in advance!
Marcus
This should please the compiler:
Objectbeing the most specific supertype of bothStringandInteger. Also there is space for improvement in your code. First of all rely onMapinterface, not on concreteHashMapimplementation. Secondly if you don’t really need theComparablefunctionality, just useMap<String, Object>. Last but not least, avoid multi-type collections and prefer strong typing.“[…]data contains strings and ints[…]” – if it’s just a map from
StringtoInteger: