Quantcast
Channel: Why the coding should be "to the interface" especially for primitive datatypes? - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by soulcheck for Why the coding should be "to the interface" especially for primitive datatypes?

$
0
0

The second option limits you to always use HashMap, even if some day TreeMap could be more useful.

In the first one you can change the particular implementation easier - you only have to change one line of code. It's especially visible if you return your map from methods - the method return type doesn't have to change.

Coding to an interface also helps mocking the object during tests, but I assume that's not the case here.


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>