【发布时间】:2012-10-01 08:04:01
【问题描述】:
我想使用enum 作为键和一个对象作为值。这是示例代码sn-p:
public class DistributorAuditSection implements Comparable<DistributorAuditSection>{
private Map questionComponentsMap;
public Map getQuestionComponentsMap(){
return questionComponentsMap;
}
public void setQuestionComponentsMap(Integer key, Object questionComponents){
if((questionComponentsMap == null) || (questionComponentsMap != null && questionComponentsMap.isEmpty())){
this.questionComponentsMap = new HashMap<Integer,Object>();
}
this.questionComponentsMap.put(key,questionComponents);
}
}
它现在是一个普通的 hashmap,具有整数键和对象作为值。现在我想把它改成Enummap。这样我就可以使用enum 键。我也不知道如何使用Enummap 检索值。
【问题讨论】:
-
你试过什么?当您使用
EnumMap时会发生什么?要获得帮助,您需要更加具体并表明您已完成作业。