Run-Time Type Comparisons Within a Generic Hierarchy in java -


i unable understand text the complete reference code this,

public class generic {     public static void main(string[] args)     {         superclass<integer> s1=new superclass<>(135);         subclass<double> s2=new subclass<>(1.35);         if(s1 instanceof superclass<integer>)         {             system.out.println("i instance of superclass");         }     } }  class superclass<t> {     t y;     superclass(t ob)     {         y=ob;     }     t ret()     {         return(y);     } }  class subclass<t> extends superclass<t> {     t x;     subclass(t y)     {         super(y);         x=y;     } } 

according text,

if(s1 instanceof superclass<integer>) line can’t compiled because attempts compare s1 specific type of superclass,in case, superclass<integer>. remember, there no generic type information available @ run time. therefore, there no way instanceof know if s1 instance of superclass<integer> or not.

can please explain me these lines mean?

when .java file compiled .class file, known byte code, superclass<integer> piece of code gets converted superclass. called type erasure. @ runtime there no information generic type.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -