Most visited

Recently visited

Added in API level 1

StackTraceElement

public final class StackTraceElement
extends Object implements Serializable

java.lang.Object
   ↳ java.lang.StackTraceElement


堆栈跟踪中的元素,由getStackTrace()返回。 每个元素表示一个单独的堆栈帧。 除堆栈顶部的堆栈外,所有堆栈都表示方法调用。 堆栈顶部的框架表示生成堆栈跟踪的执行点。 通常,这是创建与堆栈跟踪对应的throwable的点。

Summary

Public constructors

StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber)

创建表示指定执行点的堆栈跟踪元素。

Public methods

boolean equals(Object obj)

如果指定的对象是另一个返回true StackTraceElement表示相同的执行点与该实例的实例。

String getClassName()

返回包含由此堆栈跟踪元素表示的执行点的类的全限定名。

String getFileName()

返回包含由此堆栈跟踪元素表示的执行点的源文件的名称。

int getLineNumber()

返回包含由此堆栈跟踪元素表示的执行点的源代码行号。

String getMethodName()

返回包含由此堆栈跟踪元素表示的执行点的方法的名称。

int hashCode()

返回此堆栈跟踪元素的哈希码值。

boolean isNativeMethod()

如果包含由此堆栈跟踪元素表示的执行点的方法是本机方法,则返回true。

String toString()

返回此堆栈跟踪元素的字符串表示形式。

Inherited methods

From class java.lang.Object

Public constructors

StackTraceElement

Added in API level 1
StackTraceElement (String declaringClass, 
                String methodName, 
                String fileName, 
                int lineNumber)

创建表示指定执行点的堆栈跟踪元素。

Parameters
declaringClass String: the fully qualified name of the class containing the execution point represented by the stack trace element
methodName String: the name of the method containing the execution point represented by the stack trace element
fileName String: the name of the file containing the execution point represented by the stack trace element, or null if this information is unavailable
lineNumber int: the line number of the source line containing the execution point represented by this stack trace element, or a negative number if this information is unavailable. A value of -2 indicates that the method containing the execution point is a native method
Throws
NullPointerException if declaringClass or methodName is null

Public methods

equals

Added in API level 1
boolean equals (Object obj)

如果指定的对象是另一个返回true StackTraceElement表示相同的执行点与该实例的实例。 两个堆栈跟踪元素ab是相等的当且仅当:

     equals(a.getFileName(), b.getFileName()) &&
     a.getLineNumber() == b.getLineNumber()) &&
     equals(a.getClassName(), b.getClassName()) &&
     equals(a.getMethodName(), b.getMethodName())
 
where equals has the semantics of Objects.equals.

Parameters
obj Object: the object to be compared with this stack trace element.
Returns
boolean true if the specified object is another StackTraceElement instance representing the same execution point as this instance.

getClassName

Added in API level 1
String getClassName ()

返回包含由此堆栈跟踪元素表示的执行点的类的全限定名。

Returns
String the fully qualified name of the Class containing the execution point represented by this stack trace element.

getFileName

Added in API level 1
String getFileName ()

返回包含由此堆栈跟踪元素表示的执行点的源文件的名称。 通常,这对应于相关class文件的SourceFile属性( 根据Java虚拟机规范 ,第4.7.7节)。 在某些系统中,名称可能指代某个文件以外的某些源代码单元,例如源存储库中的条目。

Returns
String the name of the file containing the execution point represented by this stack trace element, or null if this information is unavailable.

getLineNumber

Added in API level 1
int getLineNumber ()

返回包含由此堆栈跟踪元素表示的执行点的源代码行号。 通常,这是从相关的class文件的LineNumberTable属性( 根据Java虚拟机规范 ,第4.7.8节)得出的。

Returns
int the line number of the source line containing the execution point represented by this stack trace element, or a negative number if this information is unavailable.

getMethodName

Added in API level 1
String getMethodName ()

返回包含由此堆栈跟踪元素表示的执行点的方法的名称。 如果执行点包含在实例或类初始化程序中,则此方法将根据Java虚拟机规范的第3.9节返回适当的特殊方法名称 <init><clinit>

Returns
String the name of the method containing the execution point represented by this stack trace element.

hashCode

Added in API level 1
int hashCode ()

返回此堆栈跟踪元素的哈希码值。

Returns
int a hash code value for this object.

isNativeMethod

Added in API level 1
boolean isNativeMethod ()

如果包含由此堆栈跟踪元素表示的执行点的方法是本机方法,则返回true。

Returns
boolean true if the method containing the execution point represented by this stack trace element is a native method.

toString

Added in API level 1
String toString ()

返回此堆栈跟踪元素的字符串表示形式。 这个字符串的格式取决于实现,但下面的例子可能被认为是典型的:

  • "MyClass.mash(MyClass.java:9)" - Here, "MyClass" is the fully-qualified name of the class containing the execution point represented by this stack trace element, "mash" is the name of the method containing the execution point, "MyClass.java" is the source file containing the execution point, and "9" is the line number of the source line containing the execution point.
  • "MyClass.mash(MyClass.java)" - As above, but the line number is unavailable.
  • "MyClass.mash(Unknown Source)" - As above, but neither the file name nor the line number are available.
  • "MyClass.mash(Native Method)" - As above, but neither the file name nor the line number are available, and the method containing the execution point is known to be a native method.

Returns
String a string representation of the object.

也可以看看:

Hooray!