Get child class name from parent

前端 未结 6 583
广开言路
广开言路 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:01

    On some occasions simply this line in the parent class solves this problem. It returns the name of the "child" class (not the parent):

    this.getClass().getName() //String like "com.mycompany.myclassname"
    this.getClass().getSimpleName() //String like "myclassname"
    

    See here for further discussion: http://www.coderanch.com/t/324715/java/java/Getting-child-class-name-parent

提交回复
热议问题