Does Java have an “is kind of class” test method

后端 未结 6 1828
我寻月下人不归
我寻月下人不归 2021-02-03 22:01

I have a baseclass, Statement, which several other classes inherit from, named IfStatement, WhereStatement, etc... What is the best way t

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 22:39

    Try this:

    if (Statement.class.isInstance(obj)) {
        doStuffWithStatements((Statement) obj));
    }
    

    since Class.isInstance() method takes an object instance as a parameter.

提交回复
热议问题