Class Lookup
java.lang.Object
jdk.dynalink.linker.support.Lookup
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
FieldsModifier and TypeFieldDescriptionstatic final Lookup
A canonical Lookup object that wrapsMethodHandles.publicLookup()
. -
Constructor Summary
ConstructorsConstructorDescriptionLookup
(MethodHandles.Lookup lookup) Creates a new instance, bound to an instance ofMethodHandles.Lookup
. -
Method Summary
Modifier and TypeMethodDescriptionfindGetter
(Class<?> refc, String name, Class<?> type) Performs aMethodHandles.Lookup.findGetter(Class, String, Class)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
andNoSuchFieldException
into aNoSuchFieldError
.static MethodHandle
findOwnSpecial
(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) Given a lookup, finds usingfindSpecial(Class, String, MethodType)
a method on that lookup's class.findOwnSpecial
(String name, Class<?> rtype, Class<?>... ptypes) Finds usingfindSpecial(Class, String, MethodType)
a method on that lookup's class.static MethodHandle
findOwnStatic
(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) Given a lookup, finds usingfindStatic(Class, String, MethodType)
a method on that lookup's class.findOwnStatic
(String name, Class<?> rtype, Class<?>... ptypes) Finds usingfindStatic(Class, String, MethodType)
a method on that lookup's class.findSpecial
(Class<?> declaringClass, String name, MethodType type) Performs aMethodHandles.Lookup.findSpecial(Class, String, MethodType, Class)
on the underlying lookup.findStatic
(Class<?> declaringClass, String name, MethodType type) Performs aMethodHandles.Lookup.findStatic(Class, String, MethodType)
on the underlying lookup.findVirtual
(Class<?> declaringClass, String name, MethodType type) Performs aMethodHandles.Lookup.findVirtual(Class, String, MethodType)
on the underlying lookup.static MethodHandle
unreflect
(MethodHandles.Lookup lookup, Method m) Performs aMethodHandles.Lookup.unreflect(Method)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.Performs aMethodHandles.Lookup.unreflect(Method)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.static MethodHandle
unreflectConstructor
(MethodHandles.Lookup lookup, Constructor<?> c) Performs aMethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.Performs aMethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.Performs aMethodHandles.Lookup.unreflectGetter(Field)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.Performs aMethodHandles.Lookup.unreflectSetter(Field)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and TypeMethodDescriptionprotected Object
clone()
Creates and returns a copy of this object.boolean
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 thisObject
.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
Wakes up all threads that are waiting on this object's monitor.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
(long timeoutMillis) 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
(long timeoutMillis, int nanos) 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
A canonical Lookup object that wrapsMethodHandles.publicLookup()
.
-
-
Constructor Details
-
Lookup
Creates a new instance, bound to an instance ofMethodHandles.Lookup
.- Parameters:
lookup
- theMethodHandles.Lookup
it delegates to.
-
-
Method Details
-
unreflect
Performs aMethodHandles.Lookup.unreflect(Method)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- Parameters:
m
- the method to unreflect- Returns:
- the unreflected method handle.
- Throws:
IllegalAccessError
- if the method is inaccessible.
-
unreflect
Performs aMethodHandles.Lookup.unreflect(Method)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- Parameters:
lookup
- the lookup used to unreflectm
- the method to unreflect- Returns:
- the unreflected method handle.
- Throws:
IllegalAccessError
- if the method is inaccessible.
-
unreflectGetter
Performs aMethodHandles.Lookup.unreflectGetter(Field)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- Parameters:
f
- the field for which a getter is unreflected- Returns:
- the unreflected field getter handle.
- Throws:
IllegalAccessError
- if the getter is inaccessible.
-
findGetter
Performs aMethodHandles.Lookup.findGetter(Class, String, Class)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
andNoSuchFieldException
into aNoSuchFieldError
.- Parameters:
refc
- the class declaring the fieldname
- the name of the fieldtype
- 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
Performs aMethodHandles.Lookup.unreflectSetter(Field)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- 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
Performs aMethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- Parameters:
c
- the constructor to unreflect- Returns:
- the unreflected constructor handle.
- Throws:
IllegalAccessError
- if the constructor is inaccessible.
-
unreflectConstructor
Performs aMethodHandles.Lookup.unreflectConstructor(Constructor)
, converting any encounteredIllegalAccessException
into anIllegalAccessError
.- Parameters:
lookup
- the lookup used to unreflectc
- the constructor to unreflect- Returns:
- the unreflected constructor handle.
- Throws:
IllegalAccessError
- if the constructor is inaccessible.
-
findSpecial
Performs aMethodHandles.Lookup.findSpecial(Class, String, MethodType, Class)
on the underlying lookup. Converts any encounteredIllegalAccessException
into anIllegalAccessError
andNoSuchMethodException
into aNoSuchMethodError
.- Parameters:
declaringClass
- class declaring the methodname
- the name of the methodtype
- 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
Performs aMethodHandles.Lookup.findStatic(Class, String, MethodType)
on the underlying lookup. Converts any encounteredIllegalAccessException
into anIllegalAccessError
andNoSuchMethodException
into aNoSuchMethodError
.- Parameters:
declaringClass
- class declaring the methodname
- the name of the methodtype
- 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
Performs aMethodHandles.Lookup.findVirtual(Class, String, MethodType)
on the underlying lookup. Converts any encounteredIllegalAccessException
into anIllegalAccessError
andNoSuchMethodException
into aNoSuchMethodError
.- Parameters:
declaringClass
- class declaring the methodname
- the name of the methodtype
- 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 usingfindSpecial(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 classname
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the method- Returns:
- the method handle for the method
-
findOwnSpecial
Finds usingfindSpecial(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 thanfindSpecial
in that you can just list the parameter types, and don't have to specify lookup class.- Parameters:
name
- the name of the methodrtype
- the return type of the methodptypes
- 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 usingfindStatic(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 thanfindStatic
in that you can just list the parameter types, and don't have to specify lookup class.- Parameters:
lookup
- the lookup for the classname
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the method- Returns:
- the method handle for the method
-
findOwnStatic
Finds usingfindStatic(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 thanfindStatic
in that you can just list the parameter types, and don't have to specify lookup class.- Parameters:
name
- the name of the methodrtype
- the return type of the methodptypes
- the parameter types of the method- Returns:
- the method handle for the method
-