*(00)*

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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());
      }

 

posted on 2020-06-01 11:28  *(00)*  阅读(4840)  评论(0)    收藏  举报