Kindly, why should I supply the Generic class on the left side (variable declaration) and right side (object assignment) ? I can technically skip it left or right (see alist2, or aList2), what is the drawback of aList2 and aList3 compared to aList1 ?
ArrayList<String> aList1 = new ArrayList<String>();
ArrayList<String> aList2 = new ArrayList();
ArrayList aList3 = new ArrayList<String>();
Bonus question, just came into my mind and it compiles, but what would that mean for aList4 and aList5?
ArrayList<String> aList4 = new ArrayList<>();
ArrayList<?> aList5 = new ArrayList<String>();
Thank you in advance.
Kind regards, Hermann
ArrayList<Car>With aList3, you'd have to cast any item from it into a Car. Vice versa, without generics on the right, you're adding things as objects, which are technically valid, but you wouldn't want to add an object of typeCarto an ArrayList intended to store objects of typePerson