Possible Duplicate:
What does it mean to “program to an interface”?
I noticed that some people like to declare an object as one of the interfaces it implements even though, within the scope of the variable, it is not necessary to look at it as the interface, e.g. there is no external API that expect an interface.
For example:
Map<String, Object> someMap = new HashMap<String, Object>();
Or you can just do
HashMap<String, Object> someMap = new HashMap<String, Object>();
and avoid importing java.util.Map
altogether.
What are the advantages of declaring it through an interface (first above) as opposed to the class itself (second above)?
Thanks