This will not work because you are not getting a ClassCastException for this.
The removed list type cannot be checked at runtime.
You can get a ClassCastException when trying to get something from a list (and it turns out not to be Foo), but the list itself is just a LinkedList (not knowing what its types of elements might be).
The LinkedList<Foo> instance looks like a LinkedList<Bar> at runtime.
The reason for the warning is that the runtime system cannot guarantee that the cast you made is correct (it can check part of the LinkedList, but not the general type).
Thilo source share