类Test
是我的单独类,它有两个字段String
和Float
类型,我将这个类与列表集合一起使用,最终将作为值填充到HashMap
.
但是,当我尝试使用键和 List 对象(值)将 Map 填充到地图中时,Java 似乎不接受它,因为它不是有效的语法:
ArrayList <Test> list = new ArrayList <Test> ();
Map<Integer, ArrayList <Test>> mp = new HashMap<Integer, ArrayList <Test>>();
list.add(new Telephone ( 0.9 , "A"));
list.add(new Telephone(5.1 , "A"));
mp.put(0,list.get(0)); // this Does Not work :(, it should work
输出:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method put(Integer, ArrayList<Telephone>) in the type
Map<Integer,ArrayList<Telephone>> is not applicable for the arguments
(int, Telephone) at Main.main(Main.java:64)