java.lang.Object
jdk.dynalink.linker.support.Lookup
封装了
MethodHandles.Lookup,屏蔽了已检查异常。在您查找自己代码库中的方法时很有用(因此如果它们不存在,则是一个错误)。
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Lookup包装了MethodHandles.publicLookup()的规范Lookup对象。 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindGetter(Class<?> refc, String name, Class<?> type) static MethodHandlefindOwnSpecial(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) 给定一个lookup,在该lookup的类上使用findSpecial(Class, String, MethodType)查找一个方法。findOwnSpecial(String name, Class<?> rtype, Class<?>... ptypes) 使用findSpecial(Class, String, MethodType)在该lookup的类上查找一个方法。static MethodHandlefindOwnStatic(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) 给定一个lookup,在该lookup的类上使用findStatic(Class, String, MethodType)查找一个方法。findOwnStatic(String name, Class<?> rtype, Class<?>... ptypes) 使用findStatic(Class, String, MethodType)在该lookup的类上查找一个方法。findSpecial(Class<?> declaringClass, String name, MethodType type) findStatic(Class<?> declaringClass, String name, MethodType type) findVirtual(Class<?> declaringClass, String name, MethodType type) static MethodHandleunreflect(MethodHandles.Lookup lookup, Method m) static MethodHandleunreflectConstructor(MethodHandles.Lookup lookup, Constructor<?> c)
-
Field Details
-
PUBLIC
包装了MethodHandles.publicLookup()的规范Lookup对象。
-
-
Constructor Details
-
Lookup
创建一个新实例,绑定到MethodHandles.Lookup的实例。- 参数:
-
lookup- 它委托给的MethodHandles.Lookup。
-
-
Method Details
-
unreflect
- 参数:
-
m- 要反射的方法 - 返回:
- 反射后的方法句柄。
- 抛出:
-
IllegalAccessError- 如果方法不可访问。
-
unreflect
- 参数:
-
lookup- 用于反射的lookup -
m- 要反射的方法 - 返回:
- 反射后的方法句柄。
- 抛出:
-
IllegalAccessError- 如果方法不可访问。
-
unreflectGetter
- 参数:
-
f- 要反射其getter的字段 - 返回:
- 反射后的字段getter句柄。
- 抛出:
-
IllegalAccessError- 如果getter不可访问。
-
findGetter
执行MethodHandles.Lookup.findGetter(Class, String, Class),将遇到的任何IllegalAccessException转换为IllegalAccessError,将NoSuchFieldException转换为NoSuchFieldError。- 参数:
-
refc- 声明字段的类 -
name- 字段的名称 -
type- 字段的类型 - 返回:
- 反射后的字段getter句柄。
- 抛出:
-
IllegalAccessError- 如果字段不可访问。 -
NoSuchFieldError- 如果字段不存在。
-
unreflectSetter
- 参数:
-
f- 要反射setter的字段 - 返回:
- 反射后的字段setter句柄。
- 抛出:
-
IllegalAccessError- 如果字段不可访问。 -
NoSuchFieldError- 如果字段不存在。
-
unreflectConstructor
执行MethodHandles.Lookup.unreflectConstructor(Constructor),将遇到的任何IllegalAccessException转换为IllegalAccessError。- 参数:
-
c- 要反射的构造函数 - 返回:
- 反射后的构造函数句柄。
- 抛出:
-
IllegalAccessError- 如果构造函数不可访问。
-
unreflectConstructor
执行MethodHandles.Lookup.unreflectConstructor(Constructor),将遇到的任何IllegalAccessException转换为IllegalAccessError。- 参数:
-
lookup- 用于反射的查找 -
c- 要反射的构造函数 - 返回:
- 反射后的构造函数句柄。
- 抛出:
-
IllegalAccessError- 如果构造函数不可访问。
-
findSpecial
在底层查找上执行MethodHandles.Lookup.findSpecial(Class, String, MethodType, Class)。将遇到的任何IllegalAccessException转换为IllegalAccessError,将NoSuchMethodException转换为NoSuchMethodError。- 参数:
-
declaringClass- 声明方法的类 -
name- 方法的名称 -
type- 方法的类型 - 返回:
- 方法的方法句柄
- 抛出:
-
IllegalAccessError- 如果方法不可访问。 -
NoSuchMethodError- 如果方法不存在。
-
findStatic
在底层查找上执行MethodHandles.Lookup.findStatic(Class, String, MethodType)。将遇到的任何IllegalAccessException转换为IllegalAccessError,将NoSuchMethodException转换为NoSuchMethodError。- 参数:
-
declaringClass- 声明方法的类 -
name- 方法的名称 -
type- 方法的类型 - 返回:
- 方法的方法句柄
- 抛出:
-
IllegalAccessError- 如果方法不可访问。 -
NoSuchMethodError- 如果方法不存在。
-
findVirtual
在底层查找上执行MethodHandles.Lookup.findVirtual(Class, String, MethodType)。将遇到的任何IllegalAccessException转换为IllegalAccessError,将NoSuchMethodException转换为NoSuchMethodError。- 参数:
-
declaringClass- 声明方法的类 -
name- 方法的名称 -
type- 方法的类型 - 返回:
- 方法的方法句柄
- 抛出:
-
IllegalAccessError- 如果方法不可访问。 -
NoSuchMethodError- 如果方法不存在。
-
findOwnSpecial
public static MethodHandle findOwnSpecial(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) 给定一个查找,使用findSpecial(Class, String, MethodType)在该查找类上查找方法。在类的代码中很有用,方便链接到自己的私有方法。- 参数:
-
lookup- 类的查找 -
name- 方法的名称 -
rtype- 方法的返回类型 -
ptypes- 方法的参数类型 - 返回:
- 方法的方法句柄
-
findOwnSpecial
使用findSpecial(Class, String, MethodType)在该查找类上查找方法。在类的代码中很有用,方便链接到自己的私有方法。与findSpecial相比更方便,因为您只需列出参数类型,而不必指定查找类。- 参数:
-
name- 方法的名称 -
rtype- 方法的返回类型 -
ptypes- 方法的参数类型 - 返回:
- 方法的方法句柄
-
findOwnStatic
public static MethodHandle findOwnStatic(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) 给定一个查找,使用findStatic(Class, String, MethodType)在该查找类上查找方法。在类的代码中很有用,方便链接到自己的私有方法。比findStatic更容易使用,因为您只需列出参数类型,而不必指定查找类。- 参数:
-
lookup- 类的查找 -
name- 方法的名称 -
rtype- 方法的返回类型 -
ptypes- 方法的参数类型 - 返回:
- 方法的方法句柄
-
findOwnStatic
使用findStatic(Class, String, MethodType)在该查找类上查找方法。在类的代码中很有用,方便链接到自己的私有方法。比findStatic更容易使用,因为您只需列出参数类型,而不必指定查找类。- 参数:
-
name- 方法的名称 -
rtype- 方法的返回类型 -
ptypes- 方法的参数类型 - 返回:
- 方法的方法句柄
-