About Question enthuware.ocpjp.v11.2.3378 :
Posted: Sat Apr 10, 2021 2:45 pm
static void doElements(List l) {
l.add("abc");
}
public static void main(String[] args) {
List<Integer> l = new ArrayList<Integer>();
doElements(l);
System.out.println(l);
}
output [abc]
I tried as hard as I can but cant get that warning. Or I am missing something? but I am more amazed that it did add String to Integer List and works without exception. Whaaat?
l.add("abc");
}
public static void main(String[] args) {
List<Integer> l = new ArrayList<Integer>();
doElements(l);
System.out.println(l);
}
output [abc]
I tried as hard as I can but cant get that warning. Or I am missing something? but I am more amazed that it did add String to Integer List and works without exception. Whaaat?