首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

获取目前运行的类名,方法名

2012-12-21 
获取当前运行的类名,方法名public static void main(String[] arg){????try {???Test t new Test()???t

获取当前运行的类名,方法名

public static void main(String[] arg)
{
???? try {
??? Test t = new Test();
??? t.Log();
?? } catch (Exception e) {
??? e.printStackTrace();
?? }
}
public void Log()
{
??? System.out.println("方法名?????? "+Thread.currentThread().getStackTrace()[1].getMethodName());
???? System.out.println("类名??? "+Thread.currentThread().getStackTrace()[1].getClassName());
???? System.out.println("文件名?? " + Thread.currentThread().getStackTrace()[1].getFileName());
???? System.out.println("所在的行数 "+Thread.currentThread().getStackTrace()[1].getLineNumber());
}

热点排行