Package java.lang
Class StackTraceElement
java.lang.Object
java.lang.StackTraceElement
- All Implemented Interfaces:
Serializable
public final class StackTraceElement extends Object implements Serializable
A representation of a single stack frame. Arrays of
StackTraceElement
are stored in Throwable objects to represent the whole state of the
call stack at the time a Throwable gets thrown.- See Also:
Throwable.getStackTrace(), Serialized Form
-
Constructor Summary
Constructors Constructor Description StackTraceElement(String cls, String method, String file, int line)Constructs a newStackTraceElementfor a specified execution point. -
Method Summary
Modifier and Type Method Description booleanequals(Object obj)Compares this instance with the specified object and indicates if they are equal.StringgetClassName()Returns the fully qualified name of the class belonging to thisStackTraceElement.StringgetFileName()Returns the name of the Java source file containing class belonging to thisStackTraceElement.intgetLineNumber()Returns the line number in the source for the class belonging to thisStackTraceElement.StringgetMethodName()Returns the name of the method belonging to thisStackTraceElement.inthashCode()Returns an integer hash code for this object.booleanisNativeMethod()Indicates if the method name returned bygetMethodName()is implemented as a native method.StringtoString()Returns a string containing a concise, human-readable description of this object.
-
Constructor Details
-
StackTraceElement
Constructs a newStackTraceElementfor a specified execution point.- Parameters:
cls- the fully qualified name of the class where execution is at.method- the name of the method where execution is at.file- The name of the file where execution is at ornull.line- the line of the file where execution is at, a negative number if unknown or-2if the execution is in a native method.- Throws:
NullPointerException- ifclsormethodisnull.
-
-
Method Details
-
equals
Compares this instance with the specified object and indicates if they are equal. In order to be equal, the following conditions must be fulfilled:objmust be a stack trace element,- the method names of this stack trace element and of
objmust not benull, - the class, method and file names as well as the line number of this
stack trace element and of
objmust be equal.
- Overrides:
equalsin classObject- Parameters:
obj- the object to compare this instance with.- Returns:
trueif the specified object is equal to thisStackTraceElement;falseotherwise.- See Also:
hashCode()
-
getClassName
Returns the fully qualified name of the class belonging to thisStackTraceElement.- Returns:
- the fully qualified type name of the class
-
getFileName
Returns the name of the Java source file containing class belonging to thisStackTraceElement.- Returns:
- the name of the file, or
nullif this information is not available.
-
getLineNumber
public int getLineNumber()Returns the line number in the source for the class belonging to thisStackTraceElement.- Returns:
- the line number, or a negative number if this information is not available.
-
getMethodName
Returns the name of the method belonging to thisStackTraceElement.- Returns:
- the name of the method, or "
" if this information is not available.
-
hashCode
public int hashCode()Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually override both methods or neither method.Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
isNativeMethod
public boolean isNativeMethod()Indicates if the method name returned bygetMethodName()is implemented as a native method.- Returns:
trueif the method in which this stack trace element is executing is a native method;falseotherwise.
-
toString
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-