public interface MethodHandleInfo
Lookup.revealDirect
。
CONSTANT_MethodHandle
常数的ldc
指令。(看到java虚拟机的规范,部分4.4.8和5.4.3。)Lookup.findVirtual
,解决一个象征性的参考方法处理。符号引用由一个类、名称字符串和类型组成。Lookup.unreflect
或Lookup.unreflectSpecial
转换成一方法
处理方法。Lookup.unreflectConstructor
转换成一Constructor
处理方法。Lookup.unreflectGetter
或Lookup.unreflectSetter
转换成一Field
处理方法。Lookup
对象,可以破解任何直接的方法处理恢复符号引用的基本方法,构造函数,或场。破解必须通过一个
Lookup
等效对象,创建目标的方法处理,或具有足够的访问权限来创建一个等效的方法处理。
如果基本的方法是caller sensitive,直接法处理将被“绑定”到一个特定的查找对象调用类,用于创建它的lookup class。用不同的方法处理这类裂缝查找即使基本的方法是公共的失败(如Class.forName
)。
查找对象匹配的要求提供了一个“快速失败”的程序,否则可能会信任错误的启示的方法处理与符号信息(或来电绑定)从一个意想不到的范围内的要求。使用MethodHandles.reflectAs(java.lang.Class<T>, java.lang.invoke.MethodHandle)
重写此限制。
reference kind | descriptive name | scope | member | behavior |
---|---|---|---|---|
1 |
REF_getField |
class |
FT f; |
(T) this.f; |
2 |
REF_getStatic |
class or interface |
static FT f; |
(T) C.f; |
3 |
REF_putField |
class |
FT f; |
this.f = x; |
4 |
REF_putStatic |
class |
static FT f; |
C.f = arg; |
5 |
REF_invokeVirtual |
class |
T m(A*); |
(T) this.m(arg*); |
6 |
REF_invokeStatic |
class or interface |
static T m(A*); |
(T) C.m(arg*); |
7 |
REF_invokeSpecial |
class or interface |
T m(A*); |
(T) super.m(arg*); |
8 |
REF_newInvokeSpecial |
class |
C(A*); |
new C(arg*); |
9 |
REF_invokeInterface |
interface |
T m(A*); |
(T) this.m(arg*); |
Modifier and Type | Field and Description |
---|---|
static int |
REF_getField
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_getStatic
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_invokeInterface
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_invokeSpecial
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_invokeStatic
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_invokeVirtual
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_newInvokeSpecial
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_putField
一个直接的方法处理的参考,在
table above定义。
|
static int |
REF_putStatic
一个直接的方法处理的参考,在
table above定义。
|
Modifier and Type | Method and Description |
---|---|
类<?> |
getDeclaringClass()
返回定义破解方法处理底层成员的类的定义。
|
MethodType |
getMethodType()
返回破解符号引用的符号类型,表示为方法类型。
|
int |
getModifiers()
返回底层成员的访问改性剂。
|
String |
getName()
返回破解方法句柄的基本成员的名称。
|
int |
getReferenceKind()
返回一个引用类型的破解方法句柄,该句柄反过来又决定方法句柄的底层成员是否是构造函数、方法或字段。
|
default boolean |
isVarArgs()
确定潜在的成员是一个可变数量的方法或构造函数。
|
static String |
referenceKindToString(int referenceKind)
返回描述名称参考,在
table above定义。
|
<T extends Member> |
reflectAs(类<T> expected, MethodHandles.Lookup lookup)
将底层成员反映为方法、构造函数或字段对象。
|
static String |
toString(int kind, 类<?> defc, String name, MethodType type)
返回一个
MethodHandleInfo 字符串表示,鉴于其象征意义四部分。
|
static final int REF_getField
static final int REF_getStatic
static final int REF_putField
static final int REF_putStatic
static final int REF_invokeVirtual
static final int REF_invokeStatic
static final int REF_invokeSpecial
static final int REF_newInvokeSpecial
static final int REF_invokeInterface
int getReferenceKind()
类<?> getDeclaringClass()
String getName()
"<init>"
如果底层的成员是一个构造函数,否则它是一个简单的方法名或字段名。
MethodType getMethodType()
void
。如果它是一个非静态方法,该方法将不提
this
参数。如果它是一个字段,所请求的访问是读取字段,该方法类型将没有参数,返回字段类型。如果这是一场与请求的访问是写的领域,该方法将有一个参数字段类型和返回
void
。
请注意,原来的直接处理方法可以包括领导this
参数,或(在构造函数的情况下)将取代void
返回类型与构造类。名义型不包括任何this
参数,和(在一个构造函数的情况下)将返回void
。
<T extends Member> T reflectAs(类<T> expected, MethodHandles.Lookup lookup)
getMethod
,
getConstructor
,或
getField
。否则,它是反映如
getDeclaredMethod
,
getDeclaredConstructor
,或
getDeclaredField
。底层成员必须访问给定的查找对象。
T
-结果所期望的类型,要么
Member
或亚型
expected
-代表期望的结果类型
T
类对象
lookup
,创造了这个methodhandleinfo查找对象,或一个等效的访问权限
ClassCastException
-如果成员不是预期的类型
NullPointerException
如果任一参数是
null
IllegalArgumentException
如果底层成员不是给定的查询对象的访问
int getModifiers()
Modifier
,
reflectAs(java.lang.Class<T>, java.lang.invoke.MethodHandles.Lookup)
default boolean isVarArgs()
getReferenceKind() >= REF_invokeVirtual && Modifier.isTransient(getModifiers())
true
当且仅当底层成员变元的声明。
static String referenceKindToString(int referenceKind)
referenceKind
整数编码一种用于访问类成员的参考
"getField"
字符串
IllegalArgumentException
如果参数不是一个有效的
reference kind number
static String toString(int kind, 类<?> defc, String name, MethodType type)
MethodHandleInfo
字符串表示,鉴于其象征意义四部分。这是
"RK C.N:MT"
的形式,在
RK
是
kind
的
reference kind string,
C
是
defc
N
的
name是
name
,和
MT
是
type
。这四个值可以从
reference kind,
declaring class,
member name得到的,和一个
MethodHandleInfo
对象
method type。
String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type)
kind
-象征性的参考
reference kind部分
defc
-象征性的参考
declaring class部分
name
-象征性的参考
member name部分
type
-象征性的参考
method type部分
"RK C.N:MT"
IllegalArgumentException
-如果第一个参数不是一个有效的
reference kind number
NullPointerException
-如果任何参考的说法是
null
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.