Spec-Zone .ru
спецификации, руководства, описания, API
|
|
Java™ Platform Standard Ed. 7 DRAFT ea-b118 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.dyn.MethodType
public final class MethodType extends Object implements Type
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(A...)
and MethodHandle.invokeGeneric(A...)
, 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.
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.
When this occurs, any classes named in the descriptor strings must be loaded.
(But they need not be initialized.)
This loading may occur at any time before the MethodType
object is first derived.
Like classes and strings, method types can be represented directly
in a class file's constant pool as constants to be loaded by ldc
bytecodes.
Loading such a constant causes its component classes to be loaded as necessary.
Modifier and Type | Method and Description |
---|---|
MethodType |
changeParameterType(int num,
Class<?> nptype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
changeReturnType(Class<?> nrtype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
dropParameterType(int num)
Deprecated. Use dropParameterTypes(int, int) instead. |
MethodType |
dropParameterTypes(int start,
int end)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
boolean |
equals(Object x)
Compares the specified object with this type for equality. |
MethodType |
erase()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
fromBytecodeString(String descriptor,
ClassLoader loader)
Temporary alias for fromMethodDescriptorString; delete after M3. |
static MethodType |
fromMethodDescriptorString(String descriptor,
ClassLoader loader)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
generic()
Convenience method for genericMethodType(int) . |
static MethodType |
genericMethodType(int objectArgCount)
All parameters and the return type will be Object. |
static MethodType |
genericMethodType(int objectArgCount,
boolean varargs)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
int |
hashCode()
Returns the hash code value for this method type. |
boolean |
hasPrimitives()
Convenience method. |
boolean |
hasWrappers()
Convenience method. |
MethodType |
insertParameterType(int num,
Class<?> nptype)
Deprecated. Use insertParameterTypes(int, java.lang.Class<?>...) instead. |
MethodType |
insertParameterTypes(int num,
Class<?>... ptypesToInsert)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
insertParameterTypes(int num,
List<Class<?>> ptypesToInsert)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
make(Class<?> rtype)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?> ptype0)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?>[] ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?> ptype0,
Class<?>... ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
List<? extends Class<?>> ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
MethodType ptypes)
Deprecated. |
static MethodType |
makeGeneric(int objectArgCount)
Deprecated. |
static MethodType |
makeGeneric(int objectArgCount,
boolean varargs)
Deprecated. |
static MethodType |
methodType(Class<?> rtype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
Class<?> ptype0)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
Class<?>[] ptypes)
Find or create an instance of the given method type. |
static MethodType |
methodType(Class<?> rtype,
Class<?> ptype0,
Class<?>... ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
List<? extends Class<?>> ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
MethodType ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
Class<?>[] |
parameterArray()
Convenience method to present the arguments as an array. |
int |
parameterCount()
|
List<Class<?>> |
parameterList()
Convenience method to present the arguments as a list. |
int |
parameterSlotCount()
The number of JVM stack slots required to invoke a method of this type. |
int |
parameterSlotDepth(int num)
Number of JVM stack slots which carry all parameters including and after the given position, which must be in the range of 0 to parameterCount inclusive. |
Class<?> |
parameterType(int num)
|
int |
returnSlotCount()
The number of JVM stack slots required to receive a return value from a method of this type. |
Class<?> |
returnType()
|
String |
toBytecodeString()
Temporary alias for toMethodDescriptorString; delete after M3. |
String |
toMethodDescriptorString()
Create a bytecode descriptor representation of the method type. |
String |
toString()
The string representation of a method type is a parenthesis enclosed, comma separated list of type names, followed immediately by the return type. |
MethodType |
unwrap()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
wrap()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static MethodType methodType(Class<?> rtype, Class<?>[] ptypes)
rtype
- the return typeptypes
- the parameter typesNullPointerException
- if rtype or any ptype is nullIllegalArgumentException
- if any of the ptypes is void@Deprecated public static MethodType make(Class<?> rtype, Class<?>[] ptypes)
public static MethodType methodType(Class<?> rtype, List<? extends Class<?>> ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
@Deprecated public static MethodType make(Class<?> rtype, List<? extends Class<?>> ptypes)
public static MethodType methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
The leading parameter type is prepended to the remaining array.
@Deprecated public static MethodType make(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes)
public static MethodType methodType(Class<?> rtype)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has no parameter types.
@Deprecated public static MethodType make(Class<?> rtype)
public static MethodType methodType(Class<?> rtype, Class<?> ptype0)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has the single given parameter type.
@Deprecated public static MethodType make(Class<?> rtype, Class<?> ptype0)
public static MethodType methodType(Class<?> rtype, MethodType ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has the same parameter types as ptypes
,
and the specified return type.
@Deprecated public static MethodType make(Class<?> rtype, MethodType ptypes)
public static MethodType genericMethodType(int objectArgCount, boolean varargs)
methodType(java.lang.Class, java.lang.Class[])
.
All parameters and the return type will be Object
,
except the final varargs parameter if any, which will be Object[]
.
objectArgCount
- number of parameters (excluding the varargs parameter if any)varargs
- whether there will be a varargs parameter, of type Object[]
genericMethodType(int)
@Deprecated public static MethodType makeGeneric(int objectArgCount, boolean varargs)
public static MethodType genericMethodType(int objectArgCount)
objectArgCount
- number of parametersgenericMethodType(int, boolean)
@Deprecated public static MethodType makeGeneric(int objectArgCount)
public MethodType changeParameterType(int num, Class<?> nptype)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the index (zero-based) of the parameter type to changenptype
- a new parameter type to replace the old one with@Deprecated public MethodType insertParameterType(int num, Class<?> nptype)
insertParameterTypes(int, java.lang.Class<?>...)
instead.
insertParameterTypes(int, java.lang.Class<?>...)
.
public MethodType insertParameterTypes(int num, Class<?>... ptypesToInsert)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the position (zero-based) of the inserted parameter type(s)ptypesToInsert
- zero or more a new parameter types to insert into the parameter listpublic MethodType insertParameterTypes(int num, List<Class<?>> ptypesToInsert)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the position (zero-based) of the inserted parameter type(s)ptypesToInsert
- zero or more a new parameter types to insert into the parameter listpublic MethodType dropParameterTypes(int start, int end)
methodType(java.lang.Class, java.lang.Class[])
.
start
- the index (zero-based) of the first parameter type to removeend
- the index (greater than start
) of the first parameter type after not to remove@Deprecated public MethodType dropParameterType(int num)
dropParameterTypes(int, int)
instead.
dropParameterTypes(int, int)
.
public MethodType changeReturnType(Class<?> nrtype)
methodType(java.lang.Class, java.lang.Class[])
.
nrtype
- a return parameter type to replace the old one withpublic boolean hasPrimitives()
void
counts as a primitive.
public boolean hasWrappers()
Integer
.
The reference type java.lang.Void
counts as a wrapper.
public MethodType erase()
methodType(java.lang.Class, java.lang.Class[])
.
Erase all reference types to Object
.
All primitive types (including void
) will remain unchanged.
public MethodType generic()
genericMethodType(int)
.
Convert all types, both reference and primitive, to Object
.
The expression type.wrap().erase()
produces the same value
as type.generic()
.
public MethodType wrap()
methodType(java.lang.Class, java.lang.Class[])
.
Convert all primitive types to their corresponding wrapper types.
All reference types (including wrapper types) will remain unchanged.
A void
return type is changed to the type java.lang.Void
.
The expression type.wrap().erase()
produces the same value
as type.generic()
.
public MethodType unwrap()
methodType(java.lang.Class, java.lang.Class[])
.
Convert all wrapper types to their corresponding primitive types.
All primitive types (including void
) will remain unchanged.
A return type of java.lang.Void
is changed to void
.
public Class<?> parameterType(int num)
num
- the index (zero-based) of the desired parameter typepublic int parameterCount()
public Class<?> returnType()
public List<Class<?>> parameterList()
public Class<?>[] parameterArray()
public boolean equals(Object x)
equals
in class Object
x
- object to comparetrue
if this object is the same as the obj
argument; false
otherwise.Object.equals(Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
,
equals(Object)
,
List.hashCode()
public String toString()
If a type name is array, it the base type followed by [], rather than the Class.getName of the array type.
toString
in class Object
public int parameterSlotCount()
parameterCount()
plus the
number of long and double parameters (if any).
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
public int parameterSlotDepth(int num)
parameterCount
inclusive. Successive parameters are
more shallowly stacked, and parameters are indexed in the bytecodes
according to their trailing edge. Thus, to obtain the depth
in the outgoing call stack of parameter N
, obtain
the parameterSlotDepth
of its trailing edge
at position N+1
.
Parameters of type long
and double
occupy
two stack slots (for historical reasons) and all others occupy one.
Therefore, the number returned is the number of arguments
including and after the given parameter,
plus the number of long or double arguments
at or after after the argument for the given parameter.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
num
- an index (zero-based, inclusive) within the parameter typespublic int returnSlotCount()
return type
is void, it will be zero,
else if the return type is long or double, it will be two, else one.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader) throws IllegalArgumentException, TypeNotPresentException
methodType(java.lang.Class, java.lang.Class[])
.
Find or create an instance of the given method type.
Any class or interface name embedded in the descriptor string
will be resolved by calling ClassLoader.loadClass(java.lang.String)
on the given loader (or if it is null, on the system class loader).
Note that it is possible to encounter method types which cannot be constructed by this method, because their component types are not all reachable from a common class loader.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
descriptor
- a bytecode-level signature string "(T...)T"loader
- the class loader in which to look up the typesIllegalArgumentException
- if the string is not well-formedTypeNotPresentException
- if a named type cannot be foundpublic String toMethodDescriptorString()
Note that this is not a strict inverse of fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader)
.
Two distinct classes which share a common name but have different class loaders
will appear identical when viewed within descriptor strings.
This method is included for the benfit of applications that must
generate bytecodes that process method handles and invokedynamic.
fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader)
,
because the latter requires a suitable class loader argument.
public String toBytecodeString()
public static MethodType fromBytecodeString(String descriptor, ClassLoader loader) throws IllegalArgumentException, TypeNotPresentException
IllegalArgumentException
TypeNotPresentException
|
Java™ Platform Standard Ed. 7 DRAFT ea-b118 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1993, 2010, Oracle Corporation. All rights reserved.