:
Method 1: use common elements, i.e. on both sides
List<Integer> list = new ArrayList<Integer>();
Method 2: use the common on the left side and the diamond operator on the right side
List<Integer> list = new ArrayList<>();
Method 3: use the common on the left side only
List<Integer> list = new ArrayList();
Of the above three methods was introduced in java 7.
If you want to use generics, you must specify the type on the left for it to work. Note that the generic type restriction is chosen by the compiler after checking it at compile time.
Adding a generic only on the right will be inappropriate to you.
source
share