I was messing around with lists and got to this code (its a part of the main):
List l1 = new ArrayList<Object>();
List l2 = new ArrayList<String>();
Object t = "a";
l1.add("a");
l2.add(t);
System.out.println(l1.equals(l2));
System.out.println(l2.get(0));
The dynamic type of l2 is ArrayList(type:String) , but I managed to add an Object to it. Moreover, it said the lists are equal. I thought that maybe it casts it to String somehow, but then I tried:
Object t = 9;
And it still worked. Pretty sure it has something to do with the list being a raw type, but still, I can't understand how I can add an object to an ArrayList(type: String). Thanks in advance.