, Map, ?. , ?, , - Object Integer List<Object> - , , , Map. , :
public static void breakMyMap(Map<?, ?> m) {
m.put(new Object(), new Object());
}
:
Map<String, String> myMap = new HashMap<String, String>();
breakMyMap(myMap);
, breakMyMap , Object Map<String, String>, , String s.
, , Map<?, ?>, , , . , :
public static <K, V> Map<K, V> filterAttrs(Map<K, V> args, String... unless) {
Map<K, V> filteredAttrs = new HashMap<K, V>();
Arrays.sort(unless);
for (K o : args.keySet()) {
String attr = o.toString();
if (Arrays.binarySearch(unless, o.toString()) < 0 ) {
filteredAttrs.put(o, args.get(o));
}
}
return filteredAttrs;
}
, , K, , put .
, , , , , , . ,
Map<?, ?> filteredAttrs = Map.class.newInstance();
, Map - , , newInstance . , ( ) :
Map<K, V> filteredAttrs = args.getClass().newInstance();
, , , no-arg.
, !