Get child class name from parent

前端 未结 6 585
广开言路
广开言路 2021-02-06 21:36

I have a base class for my all of activities (ActivityBase) that itself derives from android.app.Activity. In onCreate I want to execute some conditio

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 22:27

    You can also use the .getClass() method of the parent and then check like this

    if(parent.getClass().equals(childObj.class)){
    //to do ..
    }
    

    This basically works because it returns the runtime object class. This will especially work in case of abstract classes - Tried and tested recently by me in my project.

提交回复
热议问题