Problem:
May I ask the map map=new HashMap (); Why is this, rather than map map=new map ();
Answer:
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.
The change example also proves that I understand the inversion of control in one of the core technologies of Spring MVC:
Refer to my previous article
http://blog.csdn.net/ideality_hunter/article/details/51502828
The relevant description in:
=================================================
There is such a loginaction class, when it wants to call the Adminservice's Hello () method, does not introduce the control inversion, needs its own new, introduces the control inversion, does not have the own new, directly calls on the line.
public class Loginaction extends Actionsupport
{
Private Adminservice adminservice = null;
Public String Execute () throws Exception
{
In spring MVC's inversion of control, spring MVC is just a matter of mentioning us new. So what is the purpose. The separation of interfaces and implementations makes it possible to invoke interfaces without paying attention to how they are implemented.
No control inversion is introduced
Begin
Adminservice aa=new adminserviceimp ();
String B=aa.hello ();
System.out.println ("######################### #BBBBBBBBBBBB" +b);
End
Introducing Control Inversion
Adminservice.hello ();//The code equivalent between the way and//start/End
}
=================================================