by kilink · 11y ago · 0 comments
It's also kind of a nitpick, but I disagree with his preference for Guava's Maps.newHashMap() vs new HashMap<>(). I'm pretty sure the only reason those static methods exist is because pre-Java 7 didn't have the diamond operator.
Other libraries like Immutables are safer for this purpose.
And Guava's collection creation methods are part of an intense desire to not use the new key word anywhere in application code.
http://docs.guava-libraries.googlecode.com/git/javadoc/com/g...
The collection creation methods existed because Java could perform type inference on methods but could not on constructors:
// Java 1.5
Map<String,Integer> map = new HashMap<String,Integer>();
// Guava
Map<String,Integer> map = Maps.newHashMap();
// Java 1.8 diamond notation
Map<String,Integer> map = new HashMap<>();