public final class Lookup extends Object
MethodHandles.Lookup
that masks checked exceptions. It is useful in those cases when you're looking up methods within your own codebase (therefore it is an error if they are not present).Modifier and Type | Field | Description |
---|---|---|
static final Lookup |
PUBLIC |
A canonical Lookup object that wraps MethodHandles.publicLookup() . |
Constructor | Description |
---|---|
Lookup |
Creates a new instance, bound to an instance of MethodHandles.Lookup . |
public static final Lookup PUBLIC
MethodHandles.publicLookup()
.public Lookup(MethodHandles.Lookup lookup)
MethodHandles.Lookup
.lookup
- the MethodHandles.Lookup
it delegates to.public MethodHandle unreflect(Method m)
MethodHandles.Lookup.unreflect(Method)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.m
- the method to unreflectIllegalAccessError
- if the method is inaccessible.public static MethodHandle unreflect(MethodHandles.Lookup lookup, Method m)
MethodHandles.Lookup.unreflect(Method)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.lookup
- the lookup used to unreflectm
- the method to unreflectIllegalAccessError
- if the method is inaccessible.public MethodHandle unreflectGetter(Field f)
MethodHandles.Lookup.unreflectGetter(Field)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.f
- the field for which a getter is unreflectedIllegalAccessError
- if the getter is inaccessible.public MethodHandle findGetter(Class<?> refc, String name, Class<?> type)
MethodHandles.Lookup.findGetter(Class, String, Class)
, converting any encountered IllegalAccessException
into an IllegalAccessError
and NoSuchFieldException
into a NoSuchFieldError
.refc
- the class declaring the fieldname
- the name of the fieldtype
- the type of the fieldIllegalAccessError
- if the field is inaccessible.NoSuchFieldError
- if the field does not exist.public MethodHandle unreflectSetter(Field f)
MethodHandles.Lookup.unreflectSetter(Field)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.f
- the field for which a setter is unreflectedIllegalAccessError
- if the field is inaccessible.NoSuchFieldError
- if the field does not exist.public MethodHandle unreflectConstructor(Constructor<?> c)
MethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.c
- the constructor to unreflectIllegalAccessError
- if the constructor is inaccessible.public static MethodHandle unreflectConstructor(MethodHandles.Lookup lookup, Constructor<?> c)
MethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encountered IllegalAccessException
into an IllegalAccessError
.lookup
- the lookup used to unreflectc
- the constructor to unreflectIllegalAccessError
- if the constructor is inaccessible.public MethodHandle findSpecial(Class<?> declaringClass, String name, MethodType type)
MethodHandles.Lookup.findSpecial(Class, String, MethodType, Class)
on the underlying lookup. Converts any encountered IllegalAccessException
into an IllegalAccessError
and NoSuchMethodException
into a NoSuchMethodError
.declaringClass
- class declaring the methodname
- the name of the methodtype
- the type of the methodIllegalAccessError
- if the method is inaccessible.NoSuchMethodError
- if the method does not exist.public MethodHandle findStatic(Class<?> declaringClass, String name, MethodType type)
MethodHandles.Lookup.findStatic(Class, String, MethodType)
on the underlying lookup. Converts any encountered IllegalAccessException
into an IllegalAccessError
and NoSuchMethodException
into a NoSuchMethodError
.declaringClass
- class declaring the methodname
- the name of the methodtype
- the type of the methodIllegalAccessError
- if the method is inaccessible.NoSuchMethodError
- if the method does not exist.public MethodHandle findVirtual(Class<?> declaringClass, String name, MethodType type)
MethodHandles.Lookup.findVirtual(Class, String, MethodType)
on the underlying lookup. Converts any encountered IllegalAccessException
into an IllegalAccessError
and NoSuchMethodException
into a NoSuchMethodError
.declaringClass
- class declaring the methodname
- the name of the methodtype
- the type of the methodIllegalAccessError
- if the method is inaccessible.NoSuchMethodError
- if the method does not exist.public static MethodHandle findOwnSpecial(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes)
findSpecial(Class, String, MethodType)
a method on that lookup's class. Useful in classes' code for convenient linking to their own privates.lookup
- the lookup for the classname
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the methodpublic MethodHandle findOwnSpecial(String name, Class<?> rtype, Class<?>... ptypes)
findSpecial(Class, String, MethodType)
a method on that lookup's class. Useful in classes' code for convenient linking to their own privates. It's also more convenient than findSpecial
in that you can just list the parameter types, and don't have to specify lookup class.name
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the methodpublic static MethodHandle findOwnStatic(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes)
findStatic(Class, String, MethodType)
a method on that lookup's class. Useful in classes' code for convenient linking to their own privates. It's easier to use than findStatic
in that you can just list the parameter types, and don't have to specify lookup class.lookup
- the lookup for the classname
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the methodpublic MethodHandle findOwnStatic(String name, Class<?> rtype, Class<?>... ptypes)
findStatic(Class, String, MethodType)
a method on that lookup's class. Useful in classes' code for convenient linking to their own privates. It's easier to use than findStatic
in that you can just list the parameter types, and don't have to specify lookup class.name
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the method
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.dynalink/jdk/dynalink/linker/support/Lookup.html