Top Description Fields Constructors Methods
jdk.dynalink.linker.support

public final Class Lookup

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.lang.reflect.Constructor, .Field, .Method

A wrapper around java.lang.invoke.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 TypeField and Description
private final MethodHandles.Lookup
public static final Lookup
PUBLIC

A canonical Lookup object that wraps MethodHandles#publicLookup().

Constructor Summary

AccessConstructor and Description
public
Lookup(final MethodHandles.Lookup lookup)

Creates a new instance, bound to an instance of java.lang.invoke.MethodHandles.Lookup.

Method Summary

Modifier and TypeMethod and Description
public MethodHandle

Returns:

the unreflected field getter handle.
findGetter
(final Class<?>
the class declaring the field
refc
,
final String
the name of the field
name
,
final Class<?>
the type of the field
type
)

Performs a java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class), converting any encountered IllegalAccessException into an IllegalAccessError and NoSuchFieldException into a NoSuchFieldError.

public static MethodHandle

Returns:

the method handle for the method
findOwnSpecial
(final MethodHandles.Lookup
the lookup for the class
lookup
,
final String
the name of the method
name
,
final Class<?>
the return type of the method
rtype
,
final Class<?>...
the parameter types of the method
ptypes
)

Given a lookup, finds using findSpecial(Class, String, MethodType) a method on that lookup's class.

public MethodHandle

Returns:

the method handle for the method
findOwnSpecial
(final String
the name of the method
name
,
final Class<?>
the return type of the method
rtype
,
final Class<?>...
the parameter types of the method
ptypes
)

Finds using findSpecial(Class, String, MethodType) a method on that lookup's class.

public static MethodHandle

Returns:

the method handle for the method
findOwnStatic
(final MethodHandles.Lookup
the lookup for the class
lookup
,
final String
the name of the method
name
,
final Class<?>
the return type of the method
rtype
,
final Class<?>...
the parameter types of the method
ptypes
)

Given a lookup, finds using findStatic(Class, String, MethodType) a method on that lookup's class.

public MethodHandle

Returns:

the method handle for the method
findOwnStatic
(final String
the name of the method
name
,
final Class<?>
the return type of the method
rtype
,
final Class<?>...
the parameter types of the method
ptypes
)

Finds using findStatic(Class, String, MethodType) a method on that lookup's class.

public MethodHandle

Returns:

a method handle for the method
findSpecial
(final Class<?>
class declaring the method
declaringClass
,
final String
the name of the method
name
,
final MethodType
the type of the method
type
)

Performs a java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class) on the underlying lookup.

public MethodHandle

Returns:

a method handle for the method
findStatic
(final Class<?>
class declaring the method
declaringClass
,
final String
the name of the method
name
,
final MethodType
the type of the method
type
)

Performs a java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType) on the underlying lookup.

public MethodHandle

Returns:

a method handle for the method
findVirtual
(final Class<?>
class declaring the method
declaringClass
,
final String
the name of the method
name
,
final MethodType
the type of the method
type
)

Performs a java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType) on the underlying lookup.

private static String
methodDescription(final Class<?> declaringClass, final String name, final MethodType type)

public MethodHandle

Returns:

the unreflected method handle.
unreflect
(final Method
the method to unreflect
m
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.

public static MethodHandle

Returns:

the unreflected method handle.
unreflect
(final MethodHandles.Lookup
the lookup used to unreflect
lookup
,
final Method
the method to unreflect
m
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.

public MethodHandle

Returns:

the unreflected constructor handle.
unreflectConstructor
(final Constructor<?>
the constructor to unreflect
c
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.

public static MethodHandle

Returns:

the unreflected constructor handle.
unreflectConstructor
(final MethodHandles.Lookup
the lookup used to unreflect
lookup
,
final Constructor<?>
the constructor to unreflect
c
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.

public MethodHandle

Returns:

the unreflected field getter handle.
unreflectGetter
(final Field
the field for which a getter is unreflected
f
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.

public MethodHandle

Returns:

the unreflected field setter handle.
unreflectSetter
(final Field
the field for which a setter is unreflected
f
)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lookupback to summary
private final MethodHandles.Lookup lookup
PUBLICback to summary
public static final Lookup PUBLIC

A canonical Lookup object that wraps MethodHandles#publicLookup().

Constructor Detail

Lookupback to summary
public Lookup(final MethodHandles.Lookup lookup)

Creates a new instance, bound to an instance of java.lang.invoke.MethodHandles.Lookup.

Parameters
lookup:MethodHandles.Lookup

the java.lang.invoke.MethodHandles.Lookup it delegates to.

Method Detail

findGetterback to summary
public MethodHandle findGetter(final Class<?> refc, final String name, final Class<?> type)

Performs a java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class), converting any encountered IllegalAccessException into an IllegalAccessError and NoSuchFieldException into a NoSuchFieldError.

Parameters
refc:Class<?>

the class declaring the field

name:String

the name of the field

type:Class<?>

the type of the field

Returns:MethodHandle

the unreflected field getter handle.

Exceptions
IllegalAccessError:
if the field is inaccessible.
NoSuchFieldError:
if the field does not exist.
findOwnSpecialback to summary
public static MethodHandle findOwnSpecial(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final 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:MethodHandles.Lookup

the lookup for the class

name:String

the name of the method

rtype:Class<?>

the return type of the method

ptypes:Class<?>[]

the parameter types of the method

Returns:MethodHandle

the method handle for the method

findOwnSpecialback to summary
public MethodHandle findOwnSpecial(final String name, final Class<?> rtype, final 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:String

the name of the method

rtype:Class<?>

the return type of the method

ptypes:Class<?>[]

the parameter types of the method

Returns:MethodHandle

the method handle for the method

findOwnStaticback to summary
public static MethodHandle findOwnStatic(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final 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:MethodHandles.Lookup

the lookup for the class

name:String

the name of the method

rtype:Class<?>

the return type of the method

ptypes:Class<?>[]

the parameter types of the method

Returns:MethodHandle

the method handle for the method

findOwnStaticback to summary
public MethodHandle findOwnStatic(final String name, final Class<?> rtype, final 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:String

the name of the method

rtype:Class<?>

the return type of the method

ptypes:Class<?>[]

the parameter types of the method

Returns:MethodHandle

the method handle for the method

findSpecialback to summary
public MethodHandle findSpecial(final Class<?> declaringClass, final String name, final MethodType type)

Performs a java.lang.invoke.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<?>

class declaring the method

name:String

the name of the method

type:MethodType

the type of the method

Returns:MethodHandle

a method handle for the method

Exceptions
IllegalAccessError:
if the method is inaccessible.
NoSuchMethodError:
if the method does not exist.
findStaticback to summary
public MethodHandle findStatic(final Class<?> declaringClass, final String name, final MethodType type)

Performs a java.lang.invoke.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<?>

class declaring the method

name:String

the name of the method

type:MethodType

the type of the method

Returns:MethodHandle

a method handle for the method

Exceptions
IllegalAccessError:
if the method is inaccessible.
NoSuchMethodError:
if the method does not exist.
findVirtualback to summary
public MethodHandle findVirtual(final Class<?> declaringClass, final String name, final MethodType type)

Performs a java.lang.invoke.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<?>

class declaring the method

name:String

the name of the method

type:MethodType

the type of the method

Returns:MethodHandle

a method handle for the method

Exceptions
IllegalAccessError:
if the method is inaccessible.
NoSuchMethodError:
if the method does not exist.
methodDescriptionback to summary
private static String methodDescription(final Class<?> declaringClass, final String name, final MethodType type)
unreflectback to summary
public MethodHandle unreflect(final Method m)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
m:Method

the method to unreflect

Returns:MethodHandle

the unreflected method handle.

Exceptions
IllegalAccessError:
if the method is inaccessible.
unreflectback to summary
public static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflect(Method), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
lookup:MethodHandles.Lookup

the lookup used to unreflect

m:Method

the method to unreflect

Returns:MethodHandle

the unreflected method handle.

Exceptions
IllegalAccessError:
if the method is inaccessible.
unreflectConstructorback to summary
public MethodHandle unreflectConstructor(final Constructor<?> c)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
c:Constructor<?>

the constructor to unreflect

Returns:MethodHandle

the unreflected constructor handle.

Exceptions
IllegalAccessError:
if the constructor is inaccessible.
unreflectConstructorback to summary
public static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor<?> c)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
lookup:MethodHandles.Lookup

the lookup used to unreflect

c:Constructor<?>

the constructor to unreflect

Returns:MethodHandle

the unreflected constructor handle.

Exceptions
IllegalAccessError:
if the constructor is inaccessible.
unreflectGetterback to summary
public MethodHandle unreflectGetter(final Field f)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
f:Field

the field for which a getter is unreflected

Returns:MethodHandle

the unreflected field getter handle.

Exceptions
IllegalAccessError:
if the getter is inaccessible.
unreflectSetterback to summary
public MethodHandle unreflectSetter(final Field f)

Performs a java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field), converting any encountered IllegalAccessException into an IllegalAccessError.

Parameters
f:Field

the field for which a setter is unreflected

Returns:MethodHandle

the unreflected field setter handle.

Exceptions
IllegalAccessError:
if the field is inaccessible.
NoSuchFieldError:
if the field does not exist.