I already know how to initialize Java HashMap
by using one of the following 2 ways
// way 1: apply generic type saftey
HashMap<String, Integer> hashMap1 = new HashMap<String, Integer>();
// way 2: general without apply generic type saftey
HashMap<String, Integer> hashMap2 = new HashMap();
My problem
What is the best practice
According to Eclipse Marker
Type safety: The expression of type HashMap needs unchecked conversion to conform to HashMap
new HashMap<String, Integer>();
But according to Sonar Linter
Replace the type specification in this constructor call with the diamond operator ("<>").
new HashMap();
Which one is the best? Why?