Method (Java SE 19 & JDK 19) (original) (raw)
All Superinterfaces:
[Accessible](Accessible.html "interface in com.sun.jdi")
, [Comparable](../../../../java.base/java/lang/Comparable.html "interface in java.lang")<[Method](Method.html "interface in com.sun.jdi")>
, [Locatable](Locatable.html "interface in com.sun.jdi")
, [Mirror](Mirror.html "interface in com.sun.jdi")
, [TypeComponent](TypeComponent.html "interface in com.sun.jdi")
A static or instance method in the target VM. See TypeComponent for general information about Field and Method mirrors.
Since:
1.3
See Also:
Method Summary
Returns a list containing a Location object for each executable source line in this method.
Returns a list containing a Location object for each executable source line in this method.[arguments](#arguments%28%29)()
Returns a list containing each LocalVariable that is declared as an argument of this method.
Returns a list containing a text representation of the type of each formal parameter of this method.
Returns a list containing the type of each formal parameter of this method.byte[]
[bytecodes](#bytecodes%28%29)()
Returns an array containing the bytecodes for this method.boolean
Compares the specified Object with this method for equality.int
[hashCode](#hashCode%28%29)()
Returns the hash code value for this Method.boolean
Determine if this method is abstract.boolean
[isBridge](#isBridge%28%29)()
Determine if this method is a bridge method.boolean
Determine if this method is a constructor.default boolean
[isDefault](#isDefault%28%29)()
Determine if this method is a default methodboolean
[isNative](#isNative%28%29)()
Determine if this method is native.boolean
Determine if this method is obsolete.boolean
Determine if this method is a static initializer.boolean
Determine if this method is synchronized.boolean
[isVarArgs](#isVarArgs%28%29)()
Determine if this method accepts a variable number of arguments.[location](#location%28%29)()
Returns the Location of this method, if there is executable code associated with it.[locationOfCodeIndex](#locationOfCodeIndex%28long%29)(long codeIndex)
Returns a Location for the given code index.[locationsOfLine](#locationsOfLine%28int%29)(int lineNumber)
Returns a List containing all Location objects that map to the given line number.
Returns a List containing all Location objects that map to the given line number and source name.
Returns the return type, as specified in the declaration of this method.
Returns a text representation of the return type, as specified in the declaration of this method.[variables](#variables%28%29)()
Returns a list containing each LocalVariable declared in this method.
Returns a list containing each LocalVariable of a given name in this method.
Method Details
returnTypeName
Returns a text representation of the return type, as specified in the declaration of this method.
This type name is always available even if the type has not yet been created or loaded.
Returns:
aString
containing the return type name.returnType
Returns the return type, as specified in the declaration of this method.
Note: if the return type of this method is a reference type (class, interface, or array) and it has not been created or loaded by the declaring type's class loader - that is,declaringType().classLoader()
, then ClassNotLoadedException will be thrown. Also, a reference type may have been loaded but not yet prepared, in which case the type will be returned but attempts to perform some operations on the returned type (e.g. fields()) will throw a ClassNotPreparedException. Use ReferenceType.isPrepared() to determine if a reference type is prepared.
Returns:
the return Type of this method.
Throws:
[ClassNotLoadedException](ClassNotLoadedException.html "class in com.sun.jdi")
- if the type has not yet been created or loaded through the appropriate class loader.
See Also:
* Type
* Field.type() - for usage examplesargumentTypeNames
Returns a list containing a text representation of the type of each formal parameter of this method.
This list is always available even if the types have not yet been created or loaded.
Returns:
a List of String, one List element for each parameter of this method. Each element represents the type of a formal parameter as specified at compile-time. If the formal parameter was declared with an ellipsis, then it is represented as an array of the type before the ellipsis.argumentTypes
Returns a list containing the type of each formal parameter of this method.
Note: if there is any parameter whose type is a reference type (class, interface, or array) and it has not been created or loaded by the declaring type's class loader - that is,declaringType().classLoader()
, then ClassNotLoadedException will be thrown. Also, a reference type may have been loaded but not yet prepared, in which case the list will be returned but attempts to perform some operations on the type (e.g. fields()) will throw a ClassNotPreparedException. Use ReferenceType.isPrepared() to determine if a reference type is prepared.
Returns:
return a List of Type, one List element for each parameter of this method. Each element represents the type of a formal parameter as specified at compile-time. If the formal parameter was declared with an ellipsis, then it is represented as an array of the type before the ellipsis.
Throws:
[ClassNotLoadedException](ClassNotLoadedException.html "class in com.sun.jdi")
- if the type has not yet been loaded through the appropriate class loader.
See Also:
* TypeisAbstract
boolean isAbstract()
Determine if this method is abstract.
Returns:
true
if the method is declared abstract;false
otherwise.isDefault
default boolean isDefault()
Determine if this method is a default method
Returns:
true
if the method is declared default;false
otherwise.
Since:
1.8isSynchronized
boolean isSynchronized()
Determine if this method is synchronized.
Returns:
true
if the method is declared synchronized;false
otherwise.isNative
boolean isNative()
Determine if this method is native.
Returns:
true
if the method is declared native;false
otherwise.isVarArgs
boolean isVarArgs()
Determine if this method accepts a variable number of arguments.
Returns:
true
if the method accepts a variable number of arguments,false
otherwise.
Since:
1.5isBridge
boolean isBridge()
Determine if this method is a bridge method. Bridge methods are defined inThe Java Language Specification.
Returns:
true
if the method is a bridge method,false
otherwise.
Since:
1.5isConstructor
boolean isConstructor()
Determine if this method is a constructor.
Returns:
true
if the method is a constructor;false
otherwise.isStaticInitializer
boolean isStaticInitializer()
Determine if this method is a static initializer.
Returns:
true
if the method is a static initializer;false
otherwise.isObsolete
boolean isObsolete()
Determine if this method is obsolete.
Returns:
true
if this method has been made obsolete by aVirtualMachine.redefineClasses(java.util.Map<? extends com.sun.jdi.ReferenceType, byte[]>) operation.
Since:
1.4allLineLocations
Returns a list containing a Location object for each executable source line in this method.
This method is equivalent toallLineLocations(vm.getDefaultStratum(),null)
- see allLineLocations(String,String) for more information.
Returns:
a List of all source line Location objects.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no line number information for this (non-native, non-abstract) method.allLineLocations
Returns a list containing a Location object for each executable source line in this method.
Each location maps a source line to a range of code indices. The beginning of the range can be determined throughLocation.codeIndex(). The returned list is ordered by code index (from low to high).
The returned list may contain multiple locations for a particular line number, if the compiler and/or VM has mapped that line to two or more disjoint code index ranges.
If the method is native or abstract, an empty list is returned.
Returned list is for the specified stratum (see Location for a description of strata).
Parameters:
stratum
- The stratum to retrieve information from ornull
for the ReferenceType.defaultStratum()
sourceName
- Return locations only within this source file ornull
to return locations.
Returns:
a List of all source line Location objects.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no line number information for this (non-native, non-abstract) method. Or if sourceName is non-null
and source name information is not present.
Since:
1.4locationsOfLine
Returns a List containing all Location objects that map to the given line number.
This method is equivalent tolocationsOfLine(vm.getDefaultStratum(), null, lineNumber)
- see locationsOfLine(java.lang.String,java.lang.String,int) for more information.
Parameters:
lineNumber
- the line number
Returns:
a List of Location objects that map to the given line number.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no line number information for this method.locationsOfLine
Returns a List containing all Location objects that map to the given line number and source name.
Returns a list containing each Location that maps to the given line. The returned list will contain a location for each disjoint range of code indices that have been assigned to the given line by the compiler and/or VM. Each returned location corresponds to the beginning of this range. An empty list will be returned if there is no executable code at the specified line number; specifically, native and abstract methods will always return an empty list.
Returned list is for the specified stratum (see Location for a description of strata).
Parameters:
stratum
- the stratum to use for comparing line number and source name, or null to use the default stratum
sourceName
- the source name containing the line number, or null to match all source names
lineNumber
- the line number
Returns:
a List of Location objects that map to the given line number.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no line number information for this method. Or if sourceName is non-null
and source name information is not present.
Since:
1.4locationOfCodeIndex
Location locationOfCodeIndex(long codeIndex)
Returns a Location for the given code index.
Returns:
the Location corresponding to the given code index or null if the specified code index is not a valid code index for this method (native and abstract methods will always return null).variables
Returns a list containing each LocalVariable declared in this method. The list includes any variable declared in any scope within the method. It may contain multiple variables of the same name declared within disjoint scopes. Arguments are considered local variables and will be present in the returned list. If local variable information is not available, values of actual arguments to method invocations can be obtained by using the method StackFrame.getArgumentValues()
Returns:
the list of LocalVariable objects which mirror local variables declared in this method in the target VM. If there are no local variables, a zero-length list is returned.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no variable information for this method. Generally, local variable information is not available for native or abstract methods (that is, their argument name information is not available), thus they will throw this exception.variablesByName
Returns a list containing each LocalVariable of a given name in this method. Multiple variables can be returned if the same variable name is used in disjoint scopes within the method.
Returns:
the list of LocalVariable objects of the given name. If there are no matching local variables, a zero-length list is returned.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no variable information for this method. Generally, local variable information is not available for native or abstract methods (that is, their argument name information is not available), thus they will throw this exception.arguments
Returns a list containing each LocalVariable that is declared as an argument of this method. If local variable information is not available, values of actual arguments to method invocations can be obtained by using the method StackFrame.getArgumentValues()
Returns:
the list of LocalVariable arguments. If there are no arguments, a zero-length list is returned.
Throws:
[AbsentInformationException](AbsentInformationException.html "class in com.sun.jdi")
- if there is no variable information for this method. Generally, local variable information is not available for native or abstract methods (that is, their argument name information is not available), thus they will throw this exception.bytecodes
byte[] bytecodes()
Returns an array containing the bytecodes for this method.
Not all target virtual machines support this operation. Use VirtualMachine.canGetBytecodes() to determine if the operation is supported.
Returns:
the array of bytecodes; abstract and native methods will return a zero-length array.
Throws:
[UnsupportedOperationException](../../../../java.base/java/lang/UnsupportedOperationException.html "class in java.lang")
- if the target virtual machine does not support the retrieval of bytecodes.location
Returns the Location of this method, if there is executable code associated with it.
Specified by:
[location](Locatable.html#location%28%29)
in interface[Locatable](Locatable.html "interface in com.sun.jdi")
Returns:
the Location of this mirror, or null if this is an abstract method; native methods will return a Location object whose codeIndex is -1.equals
boolean equals(Object obj)
Compares the specified Object with this method for equality.
Overrides:
[equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29)
in class[Object](../../../../java.base/java/lang/Object.html "class in java.lang")
Parameters:
obj
- the reference object with which to compare.
Returns:
true if the Object is a method and if both mirror the same method (declared in the same class or interface, in the same VM).
See Also:
* Object.hashCode()
* HashMaphashCode
int hashCode()
Returns the hash code value for this Method.
Overrides:
[hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29)
in class[Object](../../../../java.base/java/lang/Object.html "class in java.lang")
Returns:
the integer hash code.
See Also:
* Object.equals(java.lang.Object)
* System.identityHashCode(java.lang.Object)