Reputation: 6592
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.
Pair is a class that I wrote that is in my package.
I get "Cannot Instantiate the type Map>>();
Why not? Seems reasonable to me...
Upvotes: 49
Views: 78890
Reputation: 6617
Interfaces cant be intantiated You need to use some concrete class implementing the interface Try something like this
Map<String, ArrayList<Pair<String, Integer>>> k = new HashMap<String, ArrayList<Pair<String, Integer>>>();
Upvotes: 11
Reputation: 178303
The built-in Map
is an interface, which cannot be instantiated. 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.
Upvotes: 81