Class Lookup
java.lang.Object
jdk.dynalink.linker.support.Lookup
public final class Lookup extends Object
A wrapper around
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).- Since:
- 9
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
static final Lookup |
PUBLIC |
A canonical Lookup object that wraps MethodHandles.publicLookup(). |
Constructor Summary
| Constructor | Description |
|---|---|
Lookup |
Creates a new instance, bound to an instance of MethodHandles.Lookup. |
Method Summary
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
PUBLIC
public static final Lookup PUBLIC
A canonical Lookup object that wraps
MethodHandles.publicLookup().Constructor Details
Lookup
public Lookup(MethodHandles.Lookup lookup)
Creates a new instance, bound to an instance of
MethodHandles.Lookup.- Parameters:
-
lookup- theMethodHandles.Lookupit delegates to.
Method Details
unreflect
public MethodHandle unreflect(Method m)
Performs a
MethodHandles.Lookup.unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
m- the method to unreflect - Returns:
- the unreflected method handle.
- Throws:
-
IllegalAccessError- if the method is inaccessible.
unreflect
public static MethodHandle unreflect(MethodHandles.Lookup lookup, Method m)
Performs a
MethodHandles.Lookup.unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
lookup- the lookup used to unreflect -
m- the method to unreflect - Returns:
- the unreflected method handle.
- Throws:
-
IllegalAccessError- if the method is inaccessible.
unreflectGetter
public MethodHandle unreflectGetter(Field f)
Performs a
MethodHandles.Lookup.unreflectGetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
f- the field for which a getter is unreflected - Returns:
- the unreflected field getter handle.
- Throws:
-
IllegalAccessError- if the getter is inaccessible.
findGetter
public MethodHandle findGetter(Class<?> refc, String name, Class<?> type)
Performs a
MethodHandles.Lookup.findGetter(Class, String, Class), converting any encountered IllegalAccessException into an IllegalAccessError and NoSuchFieldException into a NoSuchFieldError.- Parameters:
-
refc- the class declaring the field -
name- the name of the field -
type- the type of the field - Returns:
- the unreflected field getter handle.
- Throws:
-
IllegalAccessError- if the field is inaccessible. -
NoSuchFieldError- if the field does not exist.
unreflectSetter
public MethodHandle unreflectSetter(Field f)
Performs a
MethodHandles.Lookup.unreflectSetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
f- the field for which a setter is unreflected - Returns:
- the unreflected field setter handle.
- Throws:
-
IllegalAccessError- if the field is inaccessible. -
NoSuchFieldError- if the field does not exist.
unreflectConstructor
public MethodHandle unreflectConstructor(Constructor<?> c)
Performs a
MethodHandles.Lookup.unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
c- the constructor to unreflect - Returns:
- the unreflected constructor handle.
- Throws:
-
IllegalAccessError- if the constructor is inaccessible.
unreflectConstructor
public static MethodHandle unreflectConstructor(MethodHandles.Lookup lookup, Constructor<?> c)
Performs a
MethodHandles.Lookup.unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.- Parameters:
-
lookup- the lookup used to unreflect -
c- the constructor to unreflect - Returns:
- the unreflected constructor handle.
- Throws:
-
IllegalAccessError- if the constructor is inaccessible.
findSpecial
public MethodHandle findSpecial(Class<?> declaringClass, String name, MethodType type)
Performs a
MethodHandles.Lookup.findSpecial(Class, String, MethodType, Class) on the underlying lookup. Converts any encountered IllegalAccessException into an IllegalAccessError and NoSuchMethodException into a NoSuchMethodError.- Parameters:
-
declaringClass- class declaring the method -
name- the name of the method -
type- the type of the method - Returns:
- a method handle for the method
- Throws:
-
IllegalAccessError- if the method is inaccessible. -
NoSuchMethodError- if the method does not exist.
findStatic
public MethodHandle findStatic(Class<?> declaringClass, String name, MethodType type)
Performs a
MethodHandles.Lookup.findStatic(Class, String, MethodType) on the underlying lookup. Converts any encountered IllegalAccessException into an IllegalAccessError and NoSuchMethodException into a NoSuchMethodError.- Parameters:
-
declaringClass- class declaring the method -
name- the name of the method -
type- the type of the method - Returns:
- a method handle for the method
- Throws:
-
IllegalAccessError- if the method is inaccessible. -
NoSuchMethodError- if the method does not exist.
findVirtual
public MethodHandle findVirtual(Class<?> declaringClass, String name, MethodType type)
Performs a
MethodHandles.Lookup.findVirtual(Class, String, MethodType) on the underlying lookup. Converts any encountered IllegalAccessException into an IllegalAccessError and NoSuchMethodException into a NoSuchMethodError.- Parameters:
-
declaringClass- class declaring the method -
name- the name of the method -
type- the type of the method - Returns:
- a method handle for the method
- Throws:
-
IllegalAccessError- if the method is inaccessible. -
NoSuchMethodError- if the method does not exist.
findOwnSpecial
public static MethodHandle findOwnSpecial(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes)
Given a lookup, finds using
findSpecial(Class, String, MethodType) a method on that lookup's class. Useful in classes' code for convenient linking to their own privates.- Parameters:
-
lookup- the lookup for the class -
name- the name of the method -
rtype- the return type of the method -
ptypes- the parameter types of the method - Returns:
- the method handle for the method
findOwnSpecial
public MethodHandle findOwnSpecial(String name, Class<?> rtype, Class<?>... ptypes)
Finds using
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.- Parameters:
-
name- the name of the method -
rtype- the return type of the method -
ptypes- the parameter types of the method - Returns:
- the method handle for the method
findOwnStatic
public static MethodHandle findOwnStatic(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes)
Given a lookup, finds using
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.- Parameters:
-
lookup- the lookup for the class -
name- the name of the method -
rtype- the return type of the method -
ptypes- the parameter types of the method - Returns:
- the method handle for the method
findOwnStatic
public MethodHandle findOwnStatic(String name, Class<?> rtype, Class<?>... ptypes)
Finds using
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.- Parameters:
-
name- the name of the method -
rtype- the return type of the method -
ptypes- the parameter types of the method - Returns:
- the method handle for the method
© 1993, 2025, 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.