Android获取Java类名/文件名/方法名/行号

    /**
     * Android打印方法路径
     */
    public static void printMethodPath() {
        //new 一个异常类
        Exception exception = new Exception();
        //调用者上级类名
        Log.i(TAG, "Class0———>:" + exception.getStackTrace()[0].getClassName());
        //调用者上级的上级类名
        Log.i(TAG, "Class1———>:" + exception.getStackTrace()[1].getClassName());
        //调用者上级的方法名
        Log.i(TAG, "MethodName0———>:" + exception.getStackTrace()[0].getMethodName());
        //调用者上级的上级方法名
        Log.i(TAG, "MethodName1———>:" + exception.getStackTrace()[1].getMethodName());
        //当前方法行号
        Log.i(TAG, "line0———>:" + exception.getStackTrace()[0].getLineNumber());
        //调用方法行号
        Log.i(TAG, "line1———>:" + exception.getStackTrace()[1].getLineNumber());
    }

猜你喜欢

转载自www.cnblogs.com/mjtabu/p/12111013.html
今日推荐