问题: 一、 功能目标接口,分为以下几类:
public static interface FunctionObject<T> {
void process(T object);
}
I need it generic because I d like to use T methods in the process implementations.
Then, in other generic class, I ve a Map where I have classes as keys and function objects as values:
Map<Class<T>, FunctionObject<T>> map;
但是,我也希望该地图接受基调小组的次类类别和超型功能物体,因此我这样做:
Map<Class<? extends T>, FunctionObject<? super T>> map; //not what I need
基本想法是能够使用以下地图:
//if T were Number, this should be legal
map.put(Class<Integer>, new FunctionObject<Integer>(){...});
map.put(Class<Float>, new FunctionObject<Number>(){...});
map.put(Class<Double>, new FunctionObject<Object>(){...});
由于我想要执行“功能目标”的类型是关键或超级类型,我真的要界定的是:
Map<Class<E extends T>, FunctionObject<? super E>>> map;
我如何能够取得预期的效果? 唯一选择是哪一种类型的安全异质集装箱? 地图的通用型号是什么?