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 ofsuperclass
,in case,superclass<integer>
. remember, there no generic type information available @ run time. therefore, there no wayinstanceof
know ifs1
instance ofsuperclass<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
Post a Comment