泛型类之间类似java子类型的关系

泛型类之间类似java子类型的关系,java,generics,Java,Generics,我有一个名为A的接口,它扩展了另一个接口B 我有这个密码: class myMap<T extends B> { private Map<PluginTypes, T> map; public myMap() { map = new HashMap<PluginTypes, T>(); map.put(PluginTypes.ICustomPublishingNeedsService,

我有一个名为A的接口,它扩展了另一个接口B

我有这个密码:

class myMap<T extends B> {
    private Map<PluginTypes, T> map;

    public myMap() {
        map = new HashMap<PluginTypes, T>();
        map.put(PluginTypes.ICustomPublishingNeedsService,
                A.class);
    }

}
classmymap{
私人地图;
公共myMap(){
map=新的HashMap();
map.put(PluginTypes.icustomPublishinedsService,
A.课程);
}
}
我在put函数上遇到以下编译器错误:

The method put(PluginTypes, T) in the type Map<PluginTypes,T> is not applicable for the arguments (PluginTypes, Class<A>)
类型映射中的方法put(PluginTypes,T)不适用于参数(PluginTypes,Class)
记录在案 我已经试过了

private Map<PluginTypes, Class<T>> map2;

    public myMap(int i) {
        map2 = new HashMap<PluginTypes, Class<T>>();
        map2.put(PluginTypes.ICustomPublishingNeedsService,
                (Class<T>) ICustomPublishingNeeds.class);
    }
私有地图map2;
公共myMap(int i){
map2=新的HashMap();
map2.put(PluginTypes.icustomPublishinedService,
(类别)iCustomPublishineds.Class);
}

它正在工作,但并不安全,我更希望您能帮助我纠正第一个代码中的错误,因为类不扩展A或B


myMap
表示此参数的类型将是
B
(或其子类之一)。您正在向它传递一个
Class
不扩展B.

什么是
map
要存储的?@sp00m键是枚举,键的值是接口。请告诉我一个可能的解决方案好吗?简单的解决方案是
myMap
,这不安全,我需要一个特定的接口,哪个是插件不要在地图中放置
对象。你的逻辑似乎错了。也许你的地图应该是
map
@T.J.Crowder看来我们可以把类绑定为
map