This is just an example of how the compiler catches
misuses of generic types. I just don't see why the two compiler casts in the type erasure code are needed at all here--especially why the misuse wouldn't be caught at runtime
without the (String) cast in the erasure code, which the author of the example said
was needed for this purpose.
--- Update ---
I should add that generics are not the issue here, but rather, type casting. I am quite willing to accept that the (MyNode) cast is just an artifact of the compiler and, in fact, is superfluous. However, the writer's comment regarding the (String) cast bothers me in that
some exception should be thrown without the need for the cast. The cast, though, does make it a ClassCastException, so maybe that's the point of the cast.
I think I may have answered my own question. The compiler probably casts
every expression in the type erasure code like this as a matter of course. Its(MyNode) cast
is superfluous, and its (String) cast results in a ClassCastException. A different runtime exception would result without the cast.
Thanks, Norm, for making me think this through!