How do I get the method name from within that method?

前端 未结 4 1856
天命终不由人
天命终不由人 2021-02-06 10:02

I am trying to create a function that returns the method name from within that method:

  public static String getMethodName(final int depth)
  {
    final StackT         


        
4条回答
  •  迷失自我
    2021-02-06 10:27

    Despite the fact initiating an Exception is more expensive way, I would do it anyway.

    Log.d("CurrentMethod", new Exception().getStackTrace()[0].getMethodName());
    

    Works if called in onCreate.

提交回复
热议问题