I didn't understand very well Generics and maybe the Type Erasure concepts and restrictions. So if upon the compilation process, the type information is dropped, why this code gives me an Exception at Runtime and not at compile time? I know that generics was made carefully to have compatibility to the older versions, but I didn't understand why it returns me an Exception if at Runtime the type turns into Object? Should not be at compile time? I'm sorry if you couldn't understand well, I'm not very good at speaking English.
public static void main(String[] args) {
List<String> list = new ArrayList<>();
add(list, 1l);
for(String n : lista) {
System.out.println(n);
}
}
public static void add(List l, Long lNumber ) {
l.add(lNumber);
}