Java获取文件名/类名/函数名/行号的方法

来源:互联网 发布:3d打印路径规划算法 编辑:程序博客网 时间:2024/04/27 09:29
public class Debuger {
        public static int getLineNumber()
        {
                return Thread.currentThread().getStackTrace()[2].getLineNumber();
        }


        public static String getFileName()
        {
                return Thread.currentThread().getStackTrace()[2].getFileName();
        }


        public static String getMethodName()
        {
                return Thread.currentThread().getStackTrace()[2].getMethodName() + "()";
        }


        public static String getClassName()
        {
                return Thread.currentThread().getStackTrace()[2].getClassName();
        }


        public static void print(String text)
        {
                System.out.println(text);
        }
}
原创粉丝点击