Top Description Constructors Methods
java.lang.invoke

public final Class ConstantBootstraps

extends Object
Class Inheritance
Imports
sun.invoke.util.Wrapper

Bootstrap methods for dynamically-computed constants.

The bootstrap methods in this class will throw a NullPointerException for any reference argument that is null, unless the argument is specified to be unused or specified to accept a null value.

Since
11

Constructor Summary

AccessConstructor and Description
private
ConstantBootstraps()

Do not call.

Method Summary

Modifier and TypeMethod and Description
public static VarHandle

Returns:

the VarHandle
arrayVarHandle
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
unused
name
,
Class<VarHandle>
the required result type (must be Class<VarHandle>)
type
,
Class<?>
the type of the array
arrayClass
)

Finds a VarHandle for an array type.

public static <
The enum type for which a constant value is to be returned
E extends Enum<E>
>
E

Returns:

the enum constant of the specified enum type with the specified name
enumConstant
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
the name of the constant to return, which must exactly match an enum constant in the specified type.
name
,
Class<E>
the Class object describing the enum type for which a constant is to be returned
type
)

Returns an enum constant of the type specified by type with the name specified by name.

public static Object

Returns:

the converted value
explicitCast
(MethodHandles.Lookup
unused
lookup
,
String
unused
name
,
Class<?>
the destination type of the conversion
dstType
,
Object
the value to be converted
value
)

Applies a conversion from a source type to a destination type.

public static VarHandle

Returns:

the VarHandle
fieldVarHandle
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
the name of the field
name
,
Class<VarHandle>
the required result type (must be Class<VarHandle>)
type
,
Class<?>
the class in which the field is declared
declaringClass
,
Class<?>
the type of the field
fieldType
)

Finds a VarHandle for an instance field.

public static Object

Returns:

the value of the field
getStaticFinal
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
the name of the field
name
,
Class<?>
the type of the field
type
,
Class<?>
the class in which the field is declared
declaringClass
)

Returns the value of a static final field.

public static Object

Returns:

the value of the field
getStaticFinal
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
the name of the field
name
,
Class<?>
the type of the field
type
)

Returns the value of a static final field declared in the class which is the same as the field's type (or, for primitive-valued fields, declared in the wrapper class.) This is a simplified form of getStaticFinal(MethodHandles.Lookup, String, Class, Class) for the case where a class declares distinguished constant instances of itself.

public static Object

Returns:

the result of invoking the method handle
invoke
(MethodHandles.Lookup
unused
lookup
,
String
unused
name
,
Class<?>
the desired type of the value to be returned, which must be compatible with the return type of the method handle
type
,
MethodHandle
the method handle to be invoked
handle
,
Object...
the arguments to pass to the method handle, as if with MethodHandle#invokeWithArguments. Each argument may be null.
args
)

Returns the result of invoking a method handle with the provided arguments.

pack-priv static Object
makeConstant(MethodHandle bootstrapMethod, String name, Class<?> type, Object info, Class<?> callerClass)

public static Object

Returns:

a null value
nullConstant
(MethodHandles.Lookup
unused
lookup
,
String
unused
name
,
Class<?>
a reference type
type
)

Returns a null object reference for the reference type specified by type.

public static Class<?>

Returns:

the Class mirror
primitiveClass
(MethodHandles.Lookup
unused
lookup
,
String
the descriptor (JVMS 4.3) of the desired primitive type
name
,
Class<?>
the required result type (must be Class.class)
type
)

Returns a Class mirror for the primitive type whose type descriptor is specified by name.

public static VarHandle

Returns:

the VarHandle
staticFieldVarHandle
(MethodHandles.Lookup
the lookup context describing the class performing the operation (normally stacked by the JVM)
lookup
,
String
the name of the field
name
,
Class<VarHandle>
the required result type (must be Class<VarHandle>)
type
,
Class<?>
the class in which the field is declared
declaringClass
,
Class<?>
the type of the field
fieldType
)

Finds a VarHandle for a static field.

private static <T> Class<T>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConstantBootstrapsback to summary
private ConstantBootstraps()

Do not call.

Method Detail

arrayVarHandleback to summary
public static VarHandle arrayVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> arrayClass)

Finds a VarHandle for an array type.

Parameters
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

unused

type:Class<VarHandle>

the required result type (must be Class<VarHandle>)

arrayClass:Class<?>

the type of the array

Returns:VarHandle

the VarHandle

Exceptions
IllegalAccessError:
if the component type of the array is not accessible to the class performing the operation
IllegalArgumentException:
if the type is not VarHandle
enumConstantback to summary
public static <E extends Enum<E>> E enumConstant(MethodHandles.Lookup lookup, String name, Class<E> type)

Returns an enum constant of the type specified by type with the name specified by name.

Parameters
<E>
The enum type for which a constant value is to be returned
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

the name of the constant to return, which must exactly match an enum constant in the specified type.

type:Class<E>

the Class object describing the enum type for which a constant is to be returned

Returns:E

the enum constant of the specified enum type with the specified name

Exceptions
IllegalAccessError:
if the declaring class or the field is not accessible to the class performing the operation
IllegalArgumentException:
if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type
See Also
Enum#valueOf(Class, String)
explicitCastback to summary
public static Object explicitCast(MethodHandles.Lookup lookup, String name, Class<?> dstType, Object value) throws ClassCastException

Applies a conversion from a source type to a destination type.

Given a destination type dstType and an input value value, one of the following will happen:

  • If dstType is void.class, a ClassCastException is thrown.
  • If dstType is Object.class, value is returned as is.

Otherwise one of the following conversions is applied to value:

  1. If dstType is a reference type, a reference cast is applied to value as if by calling dstType.cast(value).
  2. If dstType is a primitive type, then, if the runtime type of value is a primitive wrapper type (such as Integer), a Java unboxing conversion is applied 5.1.8 followed by a Java casting conversion 5.5 converting either directly to dstType, or, if dstType is boolean, to int, which is then converted to either true or false depending on whether the least-significant-bit is 1 or 0 respectively. If the runtime type of value is not a primitive wrapper type a ClassCastException is thrown.

The result is the same as when using the following code:

MethodHandle id = MethodHandles.identity(dstType);
MethodType mt = MethodType.methodType(dstType, Object.class);
MethodHandle conv = MethodHandles.explicitCastArguments(id, mt);
return conv.invoke(value);
Parameters
lookup:MethodHandles.Lookup

unused

name:String

unused

dstType:Class<?>

the destination type of the conversion

value:Object

the value to be converted

Returns:Object

the converted value

Exceptions
ClassCastException:
when dstType is void, when a cast per (1) fails, or when dstType is a primitive type and the runtime type of value is not a primitive wrapper type (such as Integer)
Since
15
fieldVarHandleback to summary
public static VarHandle fieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType)

Finds a VarHandle for an instance field.

Parameters
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

the name of the field

type:Class<VarHandle>

the required result type (must be Class<VarHandle>)

declaringClass:Class<?>

the class in which the field is declared

fieldType:Class<?>

the type of the field

Returns:VarHandle

the VarHandle

Exceptions
IllegalAccessError:
if the declaring class or the field is not accessible to the class performing the operation
NoSuchFieldError:
if the specified field does not exist
IllegalArgumentException:
if the type is not VarHandle
getStaticFinalback to summary
public static Object getStaticFinal(MethodHandles.Lookup lookup, String name, Class<?> type, Class<?> declaringClass)

Returns the value of a static final field.

Parameters
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

the name of the field

type:Class<?>

the type of the field

declaringClass:Class<?>

the class in which the field is declared

Returns:Object

the value of the field

Exceptions
IllegalAccessError:
if the declaring class or the field is not accessible to the class performing the operation
NoSuchFieldError:
if the specified field does not exist
IncompatibleClassChangeError:
if the specified field is not final
getStaticFinalback to summary
public static Object getStaticFinal(MethodHandles.Lookup lookup, String name, Class<?> type)

Returns the value of a static final field declared in the class which is the same as the field's type (or, for primitive-valued fields, declared in the wrapper class.) This is a simplified form of getStaticFinal(MethodHandles.Lookup, String, Class, Class) for the case where a class declares distinguished constant instances of itself.

Parameters
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

the name of the field

type:Class<?>

the type of the field

Returns:Object

the value of the field

Exceptions
IllegalAccessError:
if the declaring class or the field is not accessible to the class performing the operation
NoSuchFieldError:
if the specified field does not exist
IncompatibleClassChangeError:
if the specified field is not final
See Also
getStaticFinal(MethodHandles.Lookup, String, Class, Class)
invokeback to summary
public static Object invoke(MethodHandles.Lookup lookup, String name, Class<?> type, MethodHandle handle, Object... args) throws Throwable

Returns the result of invoking a method handle with the provided arguments.

This method behaves as if the method handle to be invoked is the result of adapting the given method handle, via MethodHandle#asType, to adjust the return type to the desired type.

Parameters
lookup:MethodHandles.Lookup

unused

name:String

unused

type:Class<?>

the desired type of the value to be returned, which must be compatible with the return type of the method handle

handle:MethodHandle

the method handle to be invoked

args:Object[]

the arguments to pass to the method handle, as if with MethodHandle#invokeWithArguments. Each argument may be null.

Returns:Object

the result of invoking the method handle

Exceptions
Throwable:
anything thrown by the method handle invocation
WrongMethodTypeException:
if the handle's method type cannot be adjusted to take the given number of arguments, or if the handle's return type cannot be adjusted to the desired type
ClassCastException:
if an argument or the result produced by invoking the handle cannot be converted by reference casting
makeConstantback to summary
pack-priv static Object makeConstant(MethodHandle bootstrapMethod, String name, Class<?> type, Object info, Class<?> callerClass)
nullConstantback to summary
public static Object nullConstant(MethodHandles.Lookup lookup, String name, Class<?> type)

Returns a null object reference for the reference type specified by type.

Parameters
lookup:MethodHandles.Lookup

unused

name:String

unused

type:Class<?>

a reference type

Returns:Object

a null value

Exceptions
IllegalArgumentException:
if type is not a reference type
primitiveClassback to summary
public static Class<?> primitiveClass(MethodHandles.Lookup lookup, String name, Class<?> type)

Returns a Class mirror for the primitive type whose type descriptor is specified by name.

Parameters
lookup:MethodHandles.Lookup

unused

name:String

the descriptor (JVMS 4.3) of the desired primitive type

type:Class<?>

the required result type (must be Class.class)

Returns:Class<?>

the Class mirror

Exceptions
IllegalArgumentException:
if the name is not a descriptor for a primitive type or the type is not Class.class
staticFieldVarHandleback to summary
public static VarHandle staticFieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType)

Finds a VarHandle for a static field.

Parameters
lookup:MethodHandles.Lookup

the lookup context describing the class performing the operation (normally stacked by the JVM)

name:String

the name of the field

type:Class<VarHandle>

the required result type (must be Class<VarHandle>)

declaringClass:Class<?>

the class in which the field is declared

fieldType:Class<?>

the type of the field

Returns:VarHandle

the VarHandle

Exceptions
IllegalAccessError:
if the declaring class or the field is not accessible to the class performing the operation
NoSuchFieldError:
if the specified field does not exist
IllegalArgumentException:
if the type is not VarHandle
validateClassAccessback to summary
private static <T> Class<T> validateClassAccess(MethodHandles.Lookup lookup, Class<T> type)