There is no difference. However, the first one is legal in Java <= 7, while the second one is legal only in Java 7 and is introduced as a short notation * . The compiler will infer the generic type from the declaration.
* Basically, the removal of redundant information and code noise reduction was introduced. So now you have:
Map<String, List<String>> myMap = new HashMap<>();
against
Map<String, List<String>> myMap = new HashMap<String, List<String>>();
The first one is much easier on the eyes.
source
share