您的位置:首页 > 编程语言 > Java开发

java 获取调用类的 类名 方法名等信息

2017-08-22 13:50 302 查看
例如:

public  void  test(){

StackTraceElement[] stacks = new Throwable().getStackTrace();


new Throwable().getStackTrace()[1].getMethodName();


aaa();

}

public void aaa(){

String name = new Throwable().getStackTrace()[1].getMethodName();


new Throwable().getStackTrace()[1].getMethodName();


System.out.println(name)

}

-------------------------

StackTraceElement: 获取调用方法的信息

.getClassName()   类名

.getLineNumber()  行号

.getMethodName();  方法名


---------------

控制台结果为:

test
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: