ArrayList list1 = new ArrayList ();
list1.add(1);
list1.add(2);
list1.add("Aman");
list1.add("Shukla");
ArrayList<String> list2 = new ArrayList<String>(list1);
list2.add("practicing");
list2.add("Java");
System.out.println("ArrayList is " + list2);
I'm expecting an error because the values that i'd entered in ArrayList list1 are Integer type and then these got copied into the ArrayList list2 of type String successfully.
Then how come is concept of Generics offering type safety?