StackTraceElement 源码阅读

StackTraceElement

  • 属性说明
/**
 *  每个 StackTraceElement 对象代表一个独立的栈帧,所有栈帧的顶部是一个方法调用
 * @since  1.4
 * @author Josh Bloch
 */
public final class StackTraceElement implements java.io.Serializable {
    /**
     *  For Throwables and StackWalker, the VM initially sets this field to a
     *  reference to the declaring Class.  The Class reference is used to
     *  construct the 'format' bitmap, and then is cleared.
     *  For STEs constructed using the public constructors, this field is not used.
     */
    private transient Class<?> declaringClassObject;

    // 通常由 JVM 初始化
    /**
     *  类加载器的名称
     */
    private String classLoaderName;
    /**
     *  模块名称
     */
    private String moduleName;
    /**
     *  模块版本
     */
    private String moduleVersion;
    /**
     *  方法声明的类
     */
    private String declaringClass;
    /**
     *  方法名称
     */
    private String methodName;
    /**
     *  文件名称
     */
    private String fileName;
    /**
     *  行号
     */
    private int    lineNumber;
    private byte   format = 0; // Default to show all
  • 常用方法
    /**
     *  获取目标类的全限定类名
     */
    public String getClassName() {
        return declaringClass;
    }

    /**
     *  获取目标方法名称
     */
    public String getMethodName() {
        return methodName;
    }

    /**
     *  获取源文件的执行行号
     */
    public int getLineNumber() {
        return lineNumber;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章