inheritance - Class equivalence in java -


a small hiccup led me basic question. intend check class equivalence in following case (academic curiosity - please not direct me instanceof or isinstance):

public class staticchild extends staticparent{     ....         public static void main(string[] args){         staticchild thisobj=new staticchild();         system.out.println(thisobj.getclass()==staticparent.class);     }  } 

this gives compilation error:

error: incomparable types: class<cap#1> , class<staticparent>                 system.out.println(thisobj.getclass()==staticparent.class);  cap#1 fresh type-variable: cap#1 extends staticchild capture of ? extends staticchild 
  1. what mean?
  2. what difference between type , class(specifically context - type , class of staticchild)?
  3. how rid of compilation error?

since thisobj declared of type staticchild, expression:

thisobj.getclass() 

returns object of type class<? extends staticchild>. trying compare object of type class<staticparent> compiler cannot match generic type parameters. knows staticparent cannot possibly extend staticchild there's nothing can assign ? in class<? extends staticchild>.

there several ways rid of error. instance, declare thisobj of type object (or of type staticparent).

note, however, test fail.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -