R
Roedy Green
Consider this code snippet:
// create a new HashMap
HashMap<String, Integer> h = new HashMap<String, Integer>(149, .75f);
....
// extract key/value pair entries into an array
Set<Map.Entry<String, String>> justEntries = h.entrySet();
Map.Entry<String, String>[] keyValuePairs =
justEntries.toArray ( new Map.Entry[justEntries.size()] );
This generates an "unchecked conversion" warning.
If put in the type like this:
// extract key/value pair entries into an array
Set<Map.Entry<String, String>> justEntries = h.entrySet();
Map.Entry<String, String>[] keyValuePairs =
justEntries.toArray ( new
Map.Entry<String,String>[justEntries.size()] );
I get an "generic array conversion error"
How are you supposed to code that.
Map.Entry is an interface and HashMap.Entry is not public. However
the problem appears to be general -- even creating arrays af HashMaps.
// create a new HashMap
HashMap<String, Integer> h = new HashMap<String, Integer>(149, .75f);
....
// extract key/value pair entries into an array
Set<Map.Entry<String, String>> justEntries = h.entrySet();
Map.Entry<String, String>[] keyValuePairs =
justEntries.toArray ( new Map.Entry[justEntries.size()] );
This generates an "unchecked conversion" warning.
If put in the type like this:
// extract key/value pair entries into an array
Set<Map.Entry<String, String>> justEntries = h.entrySet();
Map.Entry<String, String>[] keyValuePairs =
justEntries.toArray ( new
Map.Entry<String,String>[justEntries.size()] );
I get an "generic array conversion error"
How are you supposed to code that.
Map.Entry is an interface and HashMap.Entry is not public. However
the problem appears to be general -- even creating arrays af HashMaps.