Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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...

question from:https://stackoverflow.com/questions/19598369/cant-instantiate-map-well-why-not

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
80 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...