java 获取调用类的类名和方法名


String classname = new Exception().getStackTrace()[1].getClassName(); //获取调用者的类名  
  
String method_name = new Exception().getStackTrace()[1].getMethodName(); //获取调用者的方法名  

 

    StackTraceElement[] stacks = (new Throwable()).getStackTrace();
      for (StackTraceElement stack : stacks) {
        System.out.println(stack.getClassName() + "-" + stack.getMethodName());
      }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案