java.lang.Object
java.lang.runtime.SwitchBootstraps
SwitchBootstraps is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Bootstrap methods for linking
invokedynamic call sites that implement
the selection functionality of the switch statement. The bootstraps
take additional static arguments corresponding to the case labels
of the switch, implicitly numbered sequentially from [0..N).- Since:
- 17
-
Method Summary
Modifier and TypeMethodDescriptionstatic CallSitetypeSwitch(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) Bootstrap method for linking aninvokedynamiccall site that implements aswitchon a target of a reference type.
-
Method Details
-
typeSwitch
public static CallSite typeSwitch(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) throws Throwable Bootstrap method for linking aninvokedynamiccall site that implements aswitchon a target of a reference type. The static arguments are an array of case labels which must be non-null and of typeStringorIntegerorClass.The type of the returned
CallSite's method handle will have a return type ofint. It has two parameters: the first argument will be anObjectinstance (target) and the second will beint(restart).If the
targetisnull, then the method of the call site returns -1.If the
targetis notnull, then the method of the call site returns the index of the first element in thelabelsarray starting from therestartindex matching one of the following conditions:- the element is of type
Classthat is assignable from the target's class; or - the element is of type
StringorIntegerand equals to the target.
If no element in the
labelsarray matches the target, then the method of the call site return the length of thelabelsarray.- Parameters:
lookup- Represents a lookup context with the accessibility privileges of the caller. When used withinvokedynamic, this is stacked automatically by the VM.invocationName- unusedinvocationType- The invocation type of theCallSitewith two parameters, a reference type, anint, andintas a return type.labels- case labels -StringandIntegerconstants andClassinstances, in any combination- Returns:
- a
CallSitereturning the first matching element as described above - Throws:
NullPointerException- if any argument isnullIllegalArgumentException- if any element in the labels array is null, if the invocation type is not not a method type of first parameter of a reference type, second parameter of typeintand withintas its return type, or iflabelscontains an element that is not of typeString,IntegerorClass.Throwable- if there is any error linking the call site- See Java Virtual Machine Specification:
-
4.4.6 The CONSTANT_NameAndType_info Structure
4.4.10 The CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures
- the element is of type
-
SwitchBootstrapswhen preview features are enabled.