CJCoding With Joseph
15per day
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
Java Quiz #36

Raw Type and ClassCastException

hardGenerics, Classes

This code compiles (with an unchecked warning suppressed). What happens when it runs?

📄 Code

1import java.util.ArrayList;
2import java.util.List;
3 
4public class Main {
5 @SuppressWarnings("unchecked")
6 public static void main(String[] args) {
7 List<String> strings = new ArrayList<>();
8 strings.add("hello");
9 
10 List raw = strings;
11 raw.add(42);
12 
13 for (String s : strings) {
14 System.out.println(s);
15 }
16 }
17}