May be this questions is already asked, but i didn't found any words about this,
Problem: I am not getting the working of below code. Could any one please add some points in order to understand this
public static void main(String[] args) {
List list=new ArrayList<>();
list.add("String");
listOPt(list);
}
public static void listOPt(List<Integer> intList){
intList.add(343);
System.out.println(intList.toString());
}
output: [String, 343]
I am not getting how intList printing string also.
As per my understanding if we add any object before calling listOPt()
it will insert into intList
and after that function intList
accept Integer
only is it?
but how it is stored in memory?