ClassCast exception is thrown at runtime.
and all Genrics type information is removed at compile time so at runtime collections are collections like earlier days i.e befor jdk1.5 versions
and why you getting exception is explained by above post
if you are using generic it doesnt mean that you wont get ClassCastException. it depends on your programming
I understand why ClassCastException is coming. I am trying to make sense of this and trying to understand what is the ideal solution for this.
One more thing - ClassCastException comes only when assigning result of as.get() to C. If you execute as.get() and does not assign it to anything there is no ClassCastException. That means there is no casting being done if we don;t assign result to any variable?
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads: