dimanche 12 avril 2015

Java Type Erasure: Rules of cast insertion?


Vote count:

0




The Java tutorial on type erasure doesn't seem to detail the specific rules of cast insertion by the compiler. Can someone please explain the specific rules that cause the transformation detailed by the tutorial (reproduced below):



MyNode mn = new MyNode(5);
Node n = (MyNode)mn; // A raw type - compiler throws an unchecked warning
n.setData("Hello");
Integer x = (String)mn.data; // Causes a ClassCastException to be thrown.


Specifically, I'm wondering what rules cause the insertion of (MyNode) and (String). When is a cast inserted, and how is the type chosen for the cast?



asked 26 secs ago

Kvass

2,167






Java Type Erasure: Rules of cast insertion?

Aucun commentaire:

Enregistrer un commentaire