Map map=new HashMap (); Why is that so?

Source: Internet
Author: User

Map is an interface, and HashMap is an implementation of map. The interface cannot be instantiated.
Map map=new HashMap (); is to instantiate the map as a hashmap. The benefit of this is that the caller does not need to know the map specific implementation, map interface and the specific implementation of the map Java to help you do. For example, you are a leader, there are several people: Zhang San, John Doe and so on. You need to do one thing, you are concerned about whether there is someone to do, and do not care who is going to do, you just need to shout: "Somebody!" "Specifically, it doesn't matter who comes in and does things for you.
If this is said: HashMap map = new HashMap (), it is the equivalent of what you specify to Zhang San do: "To Zhang San!" ”
That's it.

Map map=new HashMap (); Why is that so?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.