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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -