我正试图找到一个解决方案(如果有的话):
public class Generics {
Map<Class<? extends SomeObject1>, SomeObject2>> map;
map = new HashMap<Class<? extends SomeObject1>, SomeObject2>>();
public static <E extends SomeObject1> SomeObject2 get(Class<E> c) {
if (map.containsKey(c))
return map.get(c);
else {
SomeObject2 o = new SomeObject2();
map.put(c, o);
return o;
}
}
}
...
//somewhere
public <T extends SomeObject1> void aMethod(AnInterestedClass<T> list) {
// How to get the value from the map
// knowing that the key is of type T?
Generics.get();
}
想法?