If you use Map<String, Object> someMap
, you are designing to an interface rather than implementation.. So you can switch between other implementation easily..
So, your Map
can point to a HashMap
, LinkedHashMap
, or any other object, that is a subclass of Map
.
So, if you have: -
Map<String, Integer> someMap = new HashMap<>();
You can change the implementation later on(If you want) to point to a LinkedHashMap
: -
someMap = new LinkedHashMap<>();
Whereas if you use HashMap
on LHS, you can only make it point to an object of type HashMap
..
But, as such there is no difference in performance.. But it is suggested to always design
to an interface
rather than implementation
..