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.
A MethodType can be described in nominal form
if and only if all of the parameter types and return type can be described
with a nominal descriptor represented by
ClassDesc. If a method type can be described nominally, then:
nominal descriptor
returned by MethodType::describeConstable.MethodType::descriptorString or
MethodType::toMethodDescriptorString
for the method type is a method descriptor (JVMS 4.3.3).
If any of the parameter types or return type cannot be described
nominally, i.e. Class::describeConstable
returns an empty optional for that type,
then the method type cannot be described nominally:
nominal descriptor and
MethodType::describeConstable returns
an empty optional.MethodType::descriptorString or
MethodType::toMethodDescriptorString
for the method type is not a type descriptor.| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private MethodTypeForm | |
| pack-priv static final ReferencedKeySet | |
| private Invokers | |
| pack-priv static final int | MAX_JVM_ARITY
This number, mandated by the JVM spec as 255, is the maximum number of slots that any Java method can receive in its argument list. |
| pack-priv static final int | MAX_MH_ARITY
This number is the maximum arity of a method handle, 254. |
| pack-priv static final int | MAX_MH_INVOKER_ARITY
This number is the maximum arity of a method handle invoker, 253. |
| private static final Class | |
| private String | |
| pack-priv static final Class | |
| private static final MethodType[] | |
| private final Class | |
| private final Class | |
| private static final ObjectStreamField[] | serialPersistentFields
There are no serializable fields for |
| private static final long | |
| private Object |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public MethodType | Returns: the same type, except with the selected parameter(s) appendedzero or more new parameter types to insert after the end of the parameter list ptypesToInsert)Finds or creates a method type with additional parameter types. |
| public MethodType | Returns: the same type, except with the selected parameter(s) appendedzero or more new parameter types to insert after the end of the parameter list ptypesToInsert)Finds or creates a method type with additional parameter types. |
| pack-priv MethodType | Returns: the resulting typeany array type arrayType, int position at which to insert parameters pos, int the number of parameter types to insert arrayLength)Delete the last parameter type and replace it with arrayLength copies of the component type of arrayType. |
| private static void | |
| pack-priv MethodType | Returns: the resulting typeany array type arrayType, int position at which to spread pos, int the number of parameter types to change arrayLength)Replace the last arrayLength parameter types with the component type of arrayType. |
| pack-priv MethodType | Returns: a version of the original type with all reference and subword types replacedErases all reference types to |
| pack-priv static boolean | |
| private boolean | |
| public MethodType | Returns: the same type, except with the selected parameter changedthe index (zero-based) of the parameter type to change num, Class<?> a new parameter type to replace the old one with nptype)Implements java. Finds or creates a method type with a single different parameter type. |
| public MethodType | Returns: the same type, except with the return type changea return parameter type to replace the old one with nrtype)Implements java. Finds or creates a method type with a different return type. |
| private static int | |
| pack-priv static void | |
| public Optional | describeConstable()
Implements java. Returns a nominal descriptor for this instance, if one can be
constructed, or an empty |
| public String | Returns: the descriptor string for this method typeImplements java. Returns the descriptor string for this method type. |
| public MethodType | Returns: the same type, except with the selected parameter(s) removedthe index (zero-based) of the first parameter type to remove start, int the index (greater than end)start) of the first parameter type after not to removeImplements java. Finds or creates a method type with some parameter types omitted. |
| pack-priv boolean | effectivelyIdenticalParameters(int skipPos, List<Class<?>> fullList)
True if my parameter list is effectively identical to the given full list, after skipping the given number of my own initial parameters. |
| public boolean | equals(Object
object to compare x)Overrides java. Compares the specified object with this type for equality. |
| private boolean | |
| public MethodType | Returns: a version of the original type with all reference types replacedErases all reference types to |
| pack-priv boolean | explicitCastEquivalentToAsType(MethodType newType)
Returns true if MHs.explicitCastArguments produces the same result as MH.asType. |
| private static boolean | explicitCastEquivalentToAsType(Class<?> src, Class<?> dst)
Reports true if the src can be converted to the dst, by both asType and MHs.eCE, and with the same effect. |
| pack-priv MethodTypeForm | |
| pack-priv static MethodType | fromDescriptor(String descriptor, ClassLoader loader)
Same as |
| public static MethodType | Returns: a method type of the given method descriptora method descriptor string descriptor, ClassLoader the class loader in which to look up the types loader)Finds or creates an instance of a method type of the given method descriptor (JVMS 4.3.3). |
| public MethodType | Returns: a version of the original type with all types replacedConverts all types, both reference and primitive, to |
| public static MethodType | Returns: a generally applicable method type, for all calls of the given fixed argument count and a collected array of further argumentsnumber of parameters (excluding the final array parameter if any) objectArgCount, boolean whether there will be a trailing array parameter, of type finalArray)Object[]Finds or creates a method type whose components are |
| public static MethodType | Returns: a generally applicable method type, for all calls of the given argument countnumber of parameters objectArgCount)Finds or creates a method type whose components are all |
| public int | Returns: the hash code value for this method typeOverrides java. Returns the hash code value for this method type. |
| public boolean | Returns: true if any of the types are primitivesReports if this type contains a primitive argument or return value. |
| public boolean | Returns: true if any of the types are wrappersReports if this type contains a wrapper argument or return value. |
| public MethodType | Returns: the same type, except with the selected parameter(s) insertedthe position (zero-based) of the inserted parameter type(s) num, Class<?>... zero or more new parameter types to insert into the parameter list ptypesToInsert)Implements java. Finds or creates a method type with additional parameter types. |
| public MethodType | Returns: the same type, except with the selected parameter(s) insertedthe position (zero-based) of the inserted parameter type(s) num, List<Class<?>> zero or more new parameter types to insert into the parameter list ptypesToInsert)Finds or creates a method type with additional parameter types. |
| pack-priv Invokers | |
| pack-priv MethodType | invokerType()
Returns: a version of the original type with MethodHandle prepended as the first argument |
| private static boolean | |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv boolean | isViewableAs(MethodType newType, boolean keepInterfaces)
True if the old return type can always be viewed (w/o casting) under new return type, and the new parameters can be viewed (w/o casting) under the old parameter types. |
| public Class | Returns: the last parameter type if any, elsevoid.classReturns the last parameter type of this method type. |
| pack-priv Class | Returns: the leading parameter type, after error checksReturn the leading parameter type, which must exist and be a reference. |
| private static Class | |
| private static MethodType | |
| public static MethodType | Returns: a method type with the given componentsthe return type rtype, Class<?>[] the parameter types ptypes)Finds or creates an instance of the given method type. |
| public static MethodType | Returns: a method type with the given componentsthe return type rtype, List<Class<?>> the parameter types ptypes)Finds or creates a method type with the given components. |
| public static MethodType | Returns: a method type with the given componentsthe return type rtype, Class<?> the first parameter type ptype0, Class<?>... the remaining parameter types ptypes)Finds or creates a method type with the given components. |
| public static MethodType | Returns: a method type with the given return valuethe return type rtype)Finds or creates a method type with the given components. |
| public static MethodType | Returns: a method type with the given return value and parameter typethe return type rtype, Class<?> the parameter type ptype0)Finds or creates a method type with the given components. |
| public static MethodType | Returns: a method type with the given componentsthe return type rtype, MethodType the method type which supplies the parameter types ptypes)Finds or creates a method type with the given components. |
| pack-priv static MethodType | |
| private static IndexOutOfBoundsException | |
| public Class | Returns: the parameter types (as a fresh copy if necessary)Implements java. Presents the parameter types as an array (a convenience method). |
| public int | Returns: the number of parameter typesImplements java. Returns the number of parameter types in this method type. |
| public List | Returns: the parameter types (as an immutable list)Implements java. Presents the parameter types as a list (a convenience method). |
| pack-priv int | Returns: the number of JVM stack slots for this type's parametersReports the number of JVM stack slots required to invoke a method of this type. |
| public Class | Returns: the selected parameter typethe index (zero-based) of the desired parameter type num)Implements java. Returns the parameter type at the specified index, within this method type. |
| pack-priv Class | |
| private void | readObject(ObjectInputStream
the stream to read the object from s)Reconstitute the |
| private Object | Returns: the fully initializedMethodType objectResolves and initializes a |
| pack-priv MethodType | Returns: the same type, except with the selected parameter(s) replacedthe position (zero-based) of the first replaced parameter type(s) start, int the position (zero-based) after the last replaced parameter type(s) end, Class<?>... zero or more new parameter types to insert into the parameter list ptypesToInsert)Finds or creates a method type with modified parameter types. |
| public Class | Returns: the return typeImplements java. Returns the return type of this method type. |
| pack-priv Class | |
| pack-priv void | |
| pack-priv static String | |
| public String | Returns: the descriptor string for this method typeReturns the descriptor string for this method type. |
| public String | toString()
Overrides java. Returns a string representation of the method type,
of the form |
| public MethodType | Returns: a version of the original type with all wrapper types replacedConverts all wrapper types to their corresponding primitive types. |
| private static MethodType | |
| public MethodType | Returns: a version of the original type with all primitive types replacedConverts all primitive types to their corresponding wrapper types. |
| private static MethodType | |
| private void | writeObject(ObjectOutputStream
the stream to write the object to s)Save the |