Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
77 views
in Technique[技术] by (71.8m points)

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

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...