MethodHandleInfo (Java SE 9 & JDK 9 ) (original) (raw)
Field Detail
* #### REF\_getField
static final int REF_getField
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FgetField)
* #### REF\_getStatic
static final int REF_getStatic
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FgetStatic)
* #### REF\_putField
static final int REF_putField
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FputField)
* #### REF\_putStatic
static final int REF_putStatic
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FputStatic)
* #### REF\_invokeVirtual
static final int REF_invokeVirtual
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FinvokeVirtual)
* #### REF\_invokeStatic
static final int REF_invokeStatic
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FinvokeStatic)
* #### REF\_invokeSpecial
static final int REF_invokeSpecial
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FinvokeSpecial)
* #### REF\_newInvokeSpecial
static final int REF_newInvokeSpecial
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FnewInvokeSpecial)
* #### REF\_invokeInterface
static final int REF_invokeInterface
A direct method handle reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds).
See Also:
[Constant Field Values](../../../constant-values.html#java.lang.invoke.MethodHandleInfo.REF%5FinvokeInterface)
Method Detail
* #### getReferenceKind
int getReferenceKind()
Returns the reference kind of the cracked method handle, which in turn determines whether the method handle's underlying member was a constructor, method, or field. See the [table above](MethodHandleInfo.html#refkinds) for definitions.
Returns:
the integer code for the kind of reference used to access the underlying member
* #### getDeclaringClass
[Class](../../../java/lang/Class.html "class in java.lang")<?> getDeclaringClass()
Returns the class in which the cracked method handle's underlying member was defined.
Returns:
the declaring class of the underlying member
* #### getName
[String](../../../java/lang/String.html "class in java.lang") getName()
Returns the name of the cracked method handle's underlying member. This is `"<init>"` if the underlying member was a constructor, else it is a simple method name or field name.
Returns:
the simple name of the underlying member
* #### getMethodType
[MethodType](../../../java/lang/invoke/MethodType.html "class in java.lang.invoke") getMethodType()
Returns the nominal type of the cracked symbolic reference, expressed as a method type. If the reference is to a constructor, the return type will be `void`. If it is to a non-static method, the method type will not mention the `this` parameter. If it is to a field and the requested access is to read the field, the method type will have no parameters and return the field type. If it is to a field and the requested access is to write the field, the method type will have one parameter of the field type and return `void`.
Note that original direct method handle may include a leading `this` parameter, or (in the case of a constructor) will replace the `void` return type with the constructed class. The nominal type does not include any `this` parameter, and (in the case of a constructor) will return `void`.
Returns:
the type of the underlying member, expressed as a method type
* #### reflectAs
<T extends [Member](../../../java/lang/reflect/Member.html "interface in java.lang.reflect")> T reflectAs([Class](../../../java/lang/Class.html "class in java.lang")<T> expected,
[MethodHandles.Lookup](../../../java/lang/invoke/MethodHandles.Lookup.html "class in java.lang.invoke") lookup)
Reflects the underlying member as a method, constructor, or field object. If the underlying member is public, it is reflected as if by`getMethod`, `getConstructor`, or `getField`. Otherwise, it is reflected as if by`getDeclaredMethod`, `getDeclaredConstructor`, or `getDeclaredField`. The underlying member must be accessible to the given lookup object.
Type Parameters:
`T` \- the desired type of the result, either [Member](../../../java/lang/reflect/Member.html "interface in java.lang.reflect") or a subtype
Parameters:
`expected` \- a class object representing the desired result type `T`
`lookup` \- the lookup object that created this MethodHandleInfo, or one with equivalent access privileges
Returns:
a reference to the method, constructor, or field object
Throws:
`[ClassCastException](../../../java/lang/ClassCastException.html "class in java.lang")` \- if the member is not of the expected type
`[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if either argument is `null`
`[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the underlying member is not accessible to the given lookup object
* #### getModifiers
int getModifiers()
Returns the access modifiers of the underlying member.
Returns:
the Java language modifiers for underlying member, or -1 if the member cannot be accessed
See Also:
[Modifier](../../../java/lang/reflect/Modifier.html "class in java.lang.reflect"), [reflectAs(java.lang.Class<T>, java.lang.invoke.MethodHandles.Lookup)](../../../java/lang/invoke/MethodHandleInfo.html#reflectAs-java.lang.Class-java.lang.invoke.MethodHandles.Lookup-)
* #### isVarArgs
default boolean isVarArgs()
Determines if the underlying member was a variable arity method or constructor. Such members are represented by method handles that are varargs collectors.
Implementation Requirements:
This produces a result equivalent to:
```
getReferenceKind() >= REF_invokeVirtual && Modifier.isTransient(getModifiers())
```
Returns:
`true` if and only if the underlying member was declared with variable arity.
* #### referenceKindToString
static [String](../../../java/lang/String.html "class in java.lang") referenceKindToString(int referenceKind)
Returns the descriptive name of the given reference kind, as defined in the [table above](MethodHandleInfo.html#refkinds). The conventional prefix "REF\_" is omitted.
Parameters:
`referenceKind` \- an integer code for a kind of reference used to access a class member
Returns:
a mixed-case string such as `"getField"`
Throws:
`[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the argument is not a valid[reference kind number](MethodHandleInfo.html#refkinds)
* #### toString
static [String](../../../java/lang/String.html "class in java.lang") toString(int kind,
[Class](../../../java/lang/Class.html "class in java.lang")<?> defc,
[String](../../../java/lang/String.html "class in java.lang") name,
[MethodType](../../../java/lang/invoke/MethodType.html "class in java.lang.invoke") type)
Returns a string representation for a `MethodHandleInfo`, given the four parts of its symbolic reference. This is defined to be of the form `"RK C.N:MT"`, where `RK` is the[reference kind string](../../../java/lang/invoke/MethodHandleInfo.html#referenceKindToString-int-) for `kind`,`C` is the [name](../../../java/lang/Class.html#getName--) of `defc` `N` is the `name`, and`MT` is the `type`. These four values may be obtained from the[reference kind](../../../java/lang/invoke/MethodHandleInfo.html#getReferenceKind--),[declaring class](../../../java/lang/invoke/MethodHandleInfo.html#getDeclaringClass--),[member name](../../../java/lang/invoke/MethodHandleInfo.html#getName--), and [method type](../../../java/lang/invoke/MethodHandleInfo.html#getMethodType--) of a `MethodHandleInfo` object.
Implementation Requirements:
This produces a result equivalent to:
```
String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type)
```
Parameters:
`kind` \- the [reference kind](../../../java/lang/invoke/MethodHandleInfo.html#getReferenceKind--) part of the symbolic reference
`defc` \- the [declaring class](../../../java/lang/invoke/MethodHandleInfo.html#getDeclaringClass--) part of the symbolic reference
`name` \- the [member name](../../../java/lang/invoke/MethodHandleInfo.html#getName--) part of the symbolic reference
`type` \- the [method type](../../../java/lang/invoke/MethodHandleInfo.html#getMethodType--) part of the symbolic reference
Returns:
a string of the form `"RK C.N:MT"`
Throws:
`[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the first argument is not a valid[reference kind number](MethodHandleInfo.html#refkinds)
`[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if any reference argument is `null`