I am very confused as to why the Integer type Arraylist is able to add a String to it. As shown, below,"("0067")" is added to the list in the addtolist(List list) method, and since it is a String the code should throw an error, but it doesn’t. Can anyone explain why this code runs successfully?
//test program
import java.util.ArrayList;
import java.util.List;
public class listing {
public static void main(String[] args) {
List<Integer> lst = new ArrayList<Integer>();
addToList(lst);
System.out.println(lst.get(0));
}
public static void addToList(List list) {
list.add("0067");
}
}