MethodType
public
final
class
MethodType
extends Object
implements
Serializable,
OfMethod<Class<?>, MethodType>
| java.lang.Object | |
| ↳ | java.lang.invoke.MethodType |
A method type represents the arguments and return type accepted and
returned by a method handle, or the arguments and return type passed
and expected by a method handle caller. Method types must be properly
matched between a method handle and all its callers,
and the JVM's operations enforce this matching at, specifically
during calls to MethodHandle.invokeExact
and MethodHandle.invoke, and during execution
of invokedynamic instructions.
The structure is a return type accompanied by any number of parameter types.
The types (primitive, void, and reference) are represented by Class objects.
(For ease of exposition, we treat void as if it were a type.
In fact, it denotes the absence of a return type.)
All instances of MethodType are immutable.
Two instances are completely interchangeable if they compare equal.
Equality depends on pairwise correspondence of the return and parameter types and on nothing else.
This type can be created only by factory methods. All factory methods may cache values, though caching is not guaranteed. Some factory methods are static, while others are virtual methods which modify precursor method types, e.g., by changing a selected parameter.
Factory methods which operate on groups of parameter types
are systematically presented in two versions, so that both Java arrays and
Java lists can be used to work with groups of parameter types.
The query methods parameterArray and parameterList
also provide a choice between arrays and lists.
MethodType objects are sometimes derived from bytecode instructions
such as invokedynamic, specifically from the type descriptor strings associated
with the instructions in a class file's constant pool.
Like classes and strings, method types can also be represented directly
in a class file's constant pool as constants.
A method type may be loaded by an ldc instruction which refers
to a suitable CONSTANT_MethodType constant pool entry.
The entry refers to a CONSTANT_Utf8 spelling for the descriptor string.
(For full details on method type constants,
see sections 4.4.8 and 5.4.3.5 of the Java Virtual Machine Specification.)
When the JVM materializes a MethodType from a descriptor string,
all classes named in the descriptor must be accessible, and will be loaded.
(But the classes need not be initialized, as is the case with a CONSTANT_Class.)
This loading may occur at any time before the MethodType object is first derived.
Summary
Public methods | ||
|---|---|---|
MethodType
|
[])">appendParameterTypes(Class...<?> ptypesToInsert)
Finds or creates a method type with additional parameter types. |
|
MethodType
|
>)">appendParameterTypes(List<Class<?>> ptypesToInsert)
Finds or creates a method type with additional parameter types. |
|
MethodType
|
)">changeParameterType(int num, Class<?> nptype)
Finds or creates a method type with a single different parameter type. |
|
MethodType
|
)">changeReturnType(Class<?> nrtype)
Finds or creates a method type with a different return type. |
|
String
|
descriptorString()
Returns a descriptor string for this method type. |
|
MethodType
|
dropParameterTypes(int start, int end)
Finds or creates a method type with some parameter types omitted. |
|
boolean
|
equals(Object x)
Compares the specified object with this type for equality. |
|
MethodType
|
erase()
Erases all reference types to |
|
static
MethodType
|
fromMethodDescriptorString(String descriptor, ClassLoader loader)
Finds or creates an instance of a method type, given the spelling of its bytecode descriptor. |
|
MethodType
|
generic()
Converts all types, both reference and primitive, to |
|
static
MethodType
|
genericMethodType(int objectArgCount, boolean finalArray)
Finds or creates a method type whose components are |
|
static
MethodType
|
genericMethodType(int objectArgCount)
Finds or creates a method type whose components are all |
|
boolean
|
hasPrimitives()
Reports if this type contains a primitive argument or return value. |
|
boolean
|
hasWrappers()
Reports if this type contains a wrapper argument or return value. |
|
int
|
hashCode()
Returns the hash code value for this method type. |
|
MethodType
|
[])">insertParameterTypes(int num, Class...<?> ptypesToInsert)
Finds or creates a method type with additional parameter types. |
|
MethodType
|
>)">insertParameterTypes(int num, List<Class<?>> ptypesToInsert)
Finds or creates a method type with additional parameter types. |
|
Class<?>
|
lastParameterType()
Returns the last parameter type of this method type. |
|
static
MethodType
|
,%20java.lang.invoke.MethodType)">methodType(Class<?> rtype, MethodType ptypes)
Finds or creates a method type with the given components. |
|
static
MethodType
|
,%20java.lang.Class[])">methodType(Class<?> rtype, Class[]<?> ptypes)
Finds or creates an instance of the given method type. |
|
static
MethodType
|
,%20java.lang.Class)">methodType(Class<?> rtype, Class<?> ptype0)
Finds or creates a method type with the given components. |
|
static
MethodType
|
)">methodType(Class<?> rtype)
Finds or creates a method type with the given components. |
|
static
MethodType
|
,%20java.util.List | |