- java.lang.Object
- 
- java.lang.invoke.ConstantBootstraps
 
- 
 public final class ConstantBootstraps extends Object Bootstrap methods for dynamically-computed constants.The bootstrap methods in this class will throw a NullPointerExceptionfor any reference argument that isnull, unless the argument is specified to be unused or specified to accept anullvalue.- Since:
- 11
 
- 
- 
Constructor SummaryConstructors Constructor Description ConstantBootstraps()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static VarHandlearrayVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> arrayClass)Finds aVarHandlefor an array type.static <E extends Enum<E>>
 EenumConstant(MethodHandles.Lookup lookup, String name, Class<E> type)Returns anenumconstant of the type specified bytypewith the name specified byname.static VarHandlefieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType)Finds aVarHandlefor an instance field.static ObjectgetStaticFinal(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.)static ObjectgetStaticFinal(MethodHandles.Lookup lookup, String name, Class<?> type, Class<?> declaringClass)Returns the value of a static final field.static Objectinvoke(MethodHandles.Lookup lookup, String name, Class<?> type, MethodHandle handle, Object... args)Returns the result of invoking a method handle with the provided arguments.static ObjectnullConstant(MethodHandles.Lookup lookup, String name, Class<?> type)Returns anullobject reference for the reference type specified bytype.static Class<?>primitiveClass(MethodHandles.Lookup lookup, String name, Class<?> type)Returns aClassmirror for the primitive type whose type descriptor is specified byname.static VarHandlestaticFieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType)Finds aVarHandlefor a static field.
 
- 
- 
- 
Method Detail- 
nullConstantpublic static Object nullConstant(MethodHandles.Lookup lookup, String name, Class<?> type) Returns anullobject reference for the reference type specified bytype.- Parameters:
- lookup- unused
- name- unused
- type- a reference type
- Returns:
- a nullvalue
- Throws:
- IllegalArgumentException- if- typeis not a reference type
 
 - 
primitiveClasspublic static Class<?> primitiveClass(MethodHandles.Lookup lookup, String name, Class<?> type) Returns aClassmirror for the primitive type whose type descriptor is specified byname.- Parameters:
- lookup- unused
- name- the descriptor (JVMS 4.3) of the desired primitive type
- type- the required result type (must be- Class.class)
- Returns:
- the Classmirror
- Throws:
- IllegalArgumentException- if the name is not a descriptor for a primitive type or the type is not- Class.class
 
 - 
enumConstantpublic static <E extends Enum<E>> E enumConstant(MethodHandles.Lookup lookup, String name, Class<E> type) Returns anenumconstant of the type specified bytypewith the name specified byname.- Type Parameters:
- E- The enum type for which a constant value is to be returned
- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- the name of the constant to return, which must exactly match an enum constant in the specified type.
- type- the- Classobject describing the enum type for which a constant is to be returned
- Returns:
- the enum constant of the specified enum type with the specified name
- Throws:
- 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)
 
 - 
getStaticFinalpublic static Object getStaticFinal(MethodHandles.Lookup lookup, String name, Class<?> type, Class<?> declaringClass) Returns the value of a static final field.- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- the name of the field
- type- the type of the field
- declaringClass- the class in which the field is declared
- Returns:
- the value of the field
- Throws:
- 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
 
 - 
getStaticFinalpublic 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 ofgetStaticFinal(MethodHandles.Lookup, String, Class, Class)for the case where a class declares distinguished constant instances of itself.- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- the name of the field
- type- the type of the field
- Returns:
- the value of the field
- Throws:
- 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)
 
 - 
invokepublic 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(java.lang.invoke.MethodType), to adjust the return type to the desired type.- Parameters:
- lookup- unused
- name- unused
- type- the desired type of the value to be returned, which must be compatible with the return type of the method handle
- handle- the method handle to be invoked
- args- the arguments to pass to the method handle, as if with- MethodHandle.invokeWithArguments(java.lang.Object...). Each argument may be- null.
- Returns:
- the result of invoking the method handle
- Throws:
- 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
- Throwable- anything thrown by the method handle invocation
 
 - 
fieldVarHandlepublic static VarHandle fieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType) Finds aVarHandlefor an instance field.- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- the name of the field
- type- the required result type (must be- Class<VarHandle>)
- declaringClass- the class in which the field is declared
- fieldType- the type of the field
- Returns:
- the VarHandle
- Throws:
- 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
 
 - 
staticFieldVarHandlepublic static VarHandle staticFieldVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> declaringClass, Class<?> fieldType) Finds aVarHandlefor a static field.- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- the name of the field
- type- the required result type (must be- Class<VarHandle>)
- declaringClass- the class in which the field is declared
- fieldType- the type of the field
- Returns:
- the VarHandle
- Throws:
- 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
 
 - 
arrayVarHandlepublic static VarHandle arrayVarHandle(MethodHandles.Lookup lookup, String name, Class<VarHandle> type, Class<?> arrayClass) Finds aVarHandlefor an array type.- Parameters:
- lookup- the lookup context describing the class performing the operation (normally stacked by the JVM)
- name- unused
- type- the required result type (must be- Class<VarHandle>)
- arrayClass- the type of the array
- Returns:
- the VarHandle
- Throws:
- IllegalAccessError- if the component type of the array is not accessible to the class performing the operation
- IllegalArgumentException- if the type is not- VarHandle
 
 
- 
 
-