2 ms·
Do something like the Google Collections Library does: HashMap<String, Integer> foo = Maps.newHashMap(); The return type of newHashMap is determined by th
by mhansen 16y ago
Do something like the Google Collections Library does:
HashMap<String, Integer> foo = Maps.newHashMap();
The return type of newHashMap is determined by the type of foo, so you don't need to repeat the generic types in angle brackets.
public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<K, V>();
}
http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Maps.html http://google-collections.googlecode.com/svn/trunk/javadoc/i...
(I'm not a fan of Java myself, but there are some tricky ways to cut down on its verbosity)
- bpodgursky 16y agoThe Collections class built into Java has a lot of timesavers like this too--singleton, singleonList, singletonMap, and Arrays has stuff like Arrays.asList( ... ). Also it's rarely important that you know the actual type of Map you're using (the interface is what's important), so you can just call Map<String, Integer> foo = Maps.newHashMap();