Module java.base
Package java.lang

Class StackTraceElement

java.lang.Object
java.lang.StackTraceElement
All Implemented Interfaces:
Serializable

public final class StackTraceElement extends Object implements Serializable
StackTraceElement represents a stack frame.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    StackTraceElement(String cls, String method, String file, int line)
    Create a StackTraceElement from the parameters.
    StackTraceElement(String classLoaderName, String module, String version, String cls, String method, String file, int line)
    Create a StackTraceElement from the parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the specified object is another StackTraceElement instance representing the same execution point as this instance.
    Returns the name of the ClassLoader used to load the class for the method in the stack frame.
    Returns the full name (i.e. including package) of the class where this stack trace element is executing.
    If available, returns the name of the file containing the Java code source which was compiled into the class where this stack trace element is executing.
    int
    Returns the source file line number for the class where this stack trace element is executing.
    Returns the name of the method where this stack trace element is executing.
    Answers the name of the module to which the execution point represented by this stack trace element belongs.
    Answers the version of the module to which the execution point represented by this stack trace element belongs.
    int
    Returns a hash code value for this stack trace element.
    boolean
    Returns true if the method name returned by getMethodName() is implemented as a native method.
    Returns a string representation of this stack trace element.

    Methods declared in class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • StackTraceElement

      public StackTraceElement(String cls, String method, String file, int line)
      Create a StackTraceElement from the parameters.
      Parameters:
      cls - The class name
      method - The method name
      file - The file name
      line - The line number
    • StackTraceElement

      public StackTraceElement(String classLoaderName, String module, String version, String cls, String method, String file, int line)
      Create a StackTraceElement from the parameters.
      Parameters:
      classLoaderName - The name for the ClassLoader
      module - The module name
      version - The module version
      cls - The class name
      method - The method name
      file - The file name
      line - The line number
      Since:
      9
  • Method Details

    • getClassLoaderName

      public String getClassLoaderName()
      Returns the name of the ClassLoader used to load the class for the method in the stack frame. See ClassLoader.getName().
      Returns:
      name of the Classloader or null
      Since:
      9
    • equals

      public boolean equals(Object obj)
      Returns true if the specified object is another StackTraceElement instance representing the same execution point as this instance.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare to
      Returns:
      boolean true if the object is the same as this object false if it is different from this object.
      See Also:
    • getModuleName

      public String getModuleName()
      Answers the name of the module to which the execution point represented by this stack trace element belongs.
      Returns:
      the name of the Module or null if it is not available
    • getModuleVersion

      public String getModuleVersion()
      Answers the version of the module to which the execution point represented by this stack trace element belongs.
      Returns:
      the version of the Module or null if it is not available.
    • getClassName

      public String getClassName()
      Returns the full name (i.e. including package) of the class where this stack trace element is executing.
      Returns:
      the name of the class where this stack trace element is executing.
    • getFileName

      public String getFileName()
      If available, returns the name of the file containing the Java code source which was compiled into the class where this stack trace element is executing.
      Returns:
      the name of the Java code source file which was compiled into the class where this stack trace element is executing. If not available, a null value is returned.
    • getLineNumber

      public int getLineNumber()
      Returns the source file line number for the class where this stack trace element is executing.
      Returns:
      the line number in the source file corresponding to where this stack trace element is executing.
    • getMethodName

      public String getMethodName()
      Returns the name of the method where this stack trace element is executing.
      Returns:
      the method in which this stack trace element is executing. Returns <unknown method> if the name of the method cannot be determined.
    • hashCode

      public int hashCode()
      Returns a hash code value for this stack trace element.
      Overrides:
      hashCode in class Object
      Returns:
      the receiver's hash.
      See Also:
    • isNativeMethod

      public boolean isNativeMethod()
      Returns true if the method name returned by getMethodName() is implemented as a native method.
      Returns:
      true if the method is a native method
    • toString

      public String toString()
      Returns a string representation of this stack trace element.
      Overrides:
      toString in class Object
      Returns:
      String a printable representation for the receiver.