Casting is a runtime operation, and at runtime generic type arguments are erased. So type parameters without an upper bound just act as regular Object types. Here's what your class looks like at runtime:
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Joined: May 18, 2012
Ok got it thank you
that means we can also cast a boolean type right???
You can cast to any generic type parameter, as long as the upper bound is a supertype of the reference you're casting. It doesn't really make much sense though, because you'd always be casting upwards, which is useless.
For instance, if the class signature was public class ImplicitConv<T extends String> then the program would throw a ClassCastException, as expected.
However, there is a compiler warning ("unchecked cast") on line 7. The compiler has been able to tell something was amiss and told you so. If you ignore or don't resolve generics-related compiler warnings, you risk getting ClassCastException at runtime.