1 回答

TA贡献1875条经验 获得超3个赞
您展示的样本在逻辑、语义和设计上都是不正确的。
您展示的课程甚至不相关,也不属于“常见”处理案例。
我使用了 2 个不同的类。
class Junior {
}
class Senior {
}
class Details<T> {
Map<T, String> allObjectMap;
public Map<T, String> getAllObjectMap() {
return allObjectMap;
}
public void setAllObjectMap(Map<T, String> allObjectMap) {
this.allObjectMap = allObjectMap;
}
}
在你的主要方法中,
HashMap<Junior, String> map1 = new HashMap<>();
HashMap<Senior, String> map2 = new HashMap<>();
Details<Junior> juniors = new Details<Junior>();
juniors.setAllObjectMap(map1);
Details<Senior> seniors = new Details<Senior>();
seniors.setAllObjectMap(map2);
如您所见,这样做是完全有可能的。
添加回答
举报