【发布时间】:2010-12-02 08:45:34
【问题描述】:
我可以使用泛型声明一个映射数组来指定映射类型:
private Map<String, Integer>[] myMaps;
但是,我不知道如何正确实例化它:
myMaps = new HashMap<String, Integer>[count]; // gives "generic array creation" error
myMaps = new HashMap[count]; // gives an "unchecked or unsafe operation" warning
myMaps = (Map<String, Integer>[])new HashMap[count]; // also gives warning
如何实例化这个映射数组而不出现编译器错误或警告?
更新:
感谢大家的回复。我最终选择了 List 建议。
【问题讨论】:
标签: java arrays generics map instantiation