2012-03-20 42 views
1

为什么我不能做这个指令?以及我能做些什么来取悦它?Instanciate在对象下的新对象

new HashMap<Integer, new java.util.ArrayList<Long>()>();

感谢

+0

请您可以接受的答案。谢谢。 – Adam 2012-12-23 17:48:34

回答

4

你大概的意思是这样的:

Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>(); 
List<Long> list = new ArrayList<Long>(); 
map.put(5, list); 
+0

exactely:D谢谢;) – Mehdi 2012-03-20 18:13:04

1

不能创建地图内一个新的实例。你只是想创建一个类型的规范。

new HashMap<Integer, List<Long>>(); 

然后,地图中的每个条目都可以指向列表的实际实例,任何类型的列表都可以。

map.put(1, new LinkedList<Long>()); 
map.put(2, new ArrayList<Long>()); 
map.put(3, new Vector<Long>()); 
1

Map map = new Hashmap<Integer,List<Long>>;

map.put(1,new ArrayList<Long>());