r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

1

u/zehydra Feb 22 '15

"HashMap<String, Set> depMap = new HashMap(); …I die a little on the inside. Because to me, that says, “depMap is a map, which is a map.”"

Sorta. It's setting a reference of type HashMap to a new HashMap.

4

u/apotheotical Feb 22 '15

First, you forgot the diamond ("new HashMap<>()"). Second, you should never assign to concrete types if possible. Always use an interface or abstract where possible (simply Map in this case). This makes it easier to swap out implementations later!