Consider below code snippet
List<Double> doubles = new ArrayList(List.of("1"));
doubles.add(1.0);
for (Double item: doubles) {
System.out.println(item.intValue());
}
Java compiler fails to detect the wrong type in ArrayList and causing runtime error.
Can anyone explain why can't java compiler detect this error in compile time?