← Back to Question List
Java Quiz #36
Raw Type and ClassCastException
This code compiles (with an unchecked warning suppressed). What happens when it runs?
📄 Code
1import java.util.ArrayList;2import java.util.List;34public class Main {5 @SuppressWarnings("unchecked")6 public static void main(String[] args) {7 List<String> strings = new ArrayList<>();8 strings.add("hello");910 List raw = strings;11 raw.add(42);1213 for (String s : strings) {14 System.out.println(s);15 }16 }17}