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 and Description |
---|---|
static Lookup |
PUBLIC
A canonical Lookup object that wraps
MethodHandles.publicLookup() . |
Constructor and Description |
---|
Lookup(MethodHandles.Lookup 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 unreflectCallerSensitive(MethodHandles.Lookup lookup, Method m)
MethodHandles.Lookup.unreflect(Method)
, of a caller sensitive method
converting any encountered IllegalAccessException
into an IllegalAccessError
.lookup
- the lookup used to unreflectm
- the method to unreflectpublic 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 unreflectConstructorCallerSensitive(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 unreflectpublic 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
Copyright © 2015, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-internal+0-2016-03-31-172659.buildd.src