Let the compiler guess the types
Saves a miniscule amount of typing; is it easier to read?
// print a frequency table of words
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(word : args) {
int freq := map.get(word); // autoboxing
map.put(word, (freq==null) ? 1 : freq+1);
}
System.out.println(map);
}
becomes
// print a frequency table of words
public static void main(String[] args) {
map := new HashMap<String, Integer>();
for(word : args) {
freq := map.get(word);
map.put(word, (freq==null) ? 1 : freq+1);
}
System.out.println(map);
}
or
public static void main(String[] args) {
final map = new HashMap<String, Integer>();
for(final word : args) {
final freq=map.get(word);
map.put(word, (freq==null) ? 1 : freq+1);
}
System.out.println(map);
}
However it's final in both cases.
Locked to the concrete class