java - Check if a object is a instance of a class (but not a instance of its subclass) -
for example:
public class foo{} public class bar extends foo{} .... void mymethod(foo qux){ if (checkinstance(qux,foo.class)){ .... } }
how can check if qux
instance of foo (but not instance of subclass of foo)? is:
- checkinstance(qux,foo.class)=true
- checkinstance(qux,bar.class)=false
is there kind of statement instanceof
check? or should use qux.getclass().equals(foo.class)
if have this, way getclass().equals(foo.class)
option you've suggested.
however, goal of oo design allow treat any foo
in same fashion. whether or not instance subclass should irrelevant in normal program.
Comments
Post a Comment