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;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章