[英]Can't Instantiate Map…well why not?
Map<String, ArrayList<Pair<String, Integer>>> k = new Map<String, ArrayList<Pair<String, Integer>>>();
This line is in my code. 这行是在我的代码中。 I'd like to instantiate a Map that contains a String then an ArrayList of Pairs of Strings and Integers.
我想实例化一个包含String的Map,然后是一对字符串和整数的ArrayList。
Pair is a class that I wrote that is in my package. Pair是我写的一个类,在我的包中。
I get "Cannot Instantiate the type Map>>(); 我得到“无法实例化类型Map >>();
Why not? 为什么不? Seems reasonable to me...
对我来说似乎合理......
The built-in Map
is an interface, which cannot be instantiated. 内置
Map
是一个无法实例化的接口。 You can choose between lots of implementing concrete classes on the right side of your assignment, such as: 您可以在作业的右侧选择许多实施具体类,例如:
ConcurrentHashMap
HashMap
LinkedHashMap
TreeMap
and many others. 和许多其他人。 The Javadocs for
Map
lists many direct concrete implementations. Javadocs for
Map
列出了许多直接的具体实现。
接口无法实例化您需要使用一些实现接口的具体类尝试这样的事情
Map<String, ArrayList<Pair<String, Integer>>> k = new HashMap<String, ArrayList<Pair<String, Integer>>>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.