Java获取当前运行方法所在的类和方法名

代码如下:

public void showClassAndMethod() {
        System.out.println(this.getClass().getSimpleName() + ":"
                + new Exception().getStackTrace()[0].getMethodName());
}

 

posted @ 2018-12-24 15:50  猪脚踏浪  阅读(2453)  评论(0编辑  收藏  举报