I understand why we could not add an element to List<? extends Number>. It is illegal to do:
So you understand that adding is "illegal"? But why is it "illegal"? Because it can violate the type safety !!
That's why I do (List<Number>)childList. What I don't understand why it doesn't throw ClassCastException when parentList.add(3.14). Because the underlying list is a ArrayList<Integer> and 3.14 is not a integer, when Java tries to implicitly convert 3.14 to integer, is it a ClassCastException?
Generics is only at compile time. ClassCastExceptions happen at runtime, when the generic type has already been erased.
IOWs, if you use generics, try your best to *not* cast anything... you need to let the generic do it's work.
Henry