Class SwitchBootstraps
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:
- 21
- 
Method SummaryModifier and TypeMethodDescriptionstatic CallSiteenumSwitch(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) Bootstrap method for linking aninvokedynamiccall site that implements aswitchon a target of an enum type.static 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- 
typeSwitchpublic static CallSite typeSwitch(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) 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 typeStringorIntegerorClassorEnumDesc.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.
- the element is of type EnumDesc, that describes a constant that is 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.The value of the restartindex must be between0(inclusive) and the length of thelabelsarray (inclusive), both or anIndexOutOfBoundsExceptionis thrown.- Parameters:
- lookup- Represents a lookup context with the accessibility privileges of the caller. When used with- invokedynamic, this is stacked automatically by the VM.
- invocationName- unused
- invocationType- The invocation type of the- CallSitewith two parameters, a reference type, an- int, and- intas a return type.
- labels- case labels -- Stringand- Integerconstants and- Classand- EnumDescinstances, in any combination
- Returns:
- a CallSitereturning the first matching element as described above
- Throws:
- NullPointerException- if any argument is- null
- IllegalArgumentException- if any element in the labels array is null
- IllegalArgumentException- if the invocation type is not a method type of first parameter of a reference type, second parameter of type- intand with- intas its return type,
- IllegalArgumentException- if- labelscontains an element that is not of type- String,- Integer,- Long,- Float,- Double,- Boolean,- Classor- EnumDesc.
- IllegalArgumentException- if- labelscontains an element that is not of type- Booleanwhen- targetis a- Boolean.class.
- 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 
- 
enumSwitchpublic static CallSite enumSwitch(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) Bootstrap method for linking aninvokedynamiccall site that implements aswitchon a target of an enum type. The static arguments are used to encode the case labels associated to the switch construct, where each label can be encoded in two ways:- as a Stringvalue, which represents the name of the enum constant associated with the label
- as a Classvalue, which represents the enum type associated with a type test pattern
 The returned CallSite's method handle will have a return type ofintand accepts two parameters: the first argument will be anEnuminstance (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 Stringand equals to the target enum constant'sEnum.name().
 If no element in the labelsarray matches the target, then the method of the call site return the length of thelabelsarray.The value of the restartindex must be between0(inclusive) and the length of thelabelsarray (inclusive), both or anIndexOutOfBoundsExceptionis thrown.- Parameters:
- lookup- Represents a lookup context with the accessibility privileges of the caller. When used with- invokedynamic, this is stacked automatically by the VM.
- invocationName- unused
- invocationType- The invocation type of the- CallSitewith two parameters, an enum type, an- int, and- intas a return type.
- labels- case labels -- Stringconstants and- Classinstances, in any combination
- Returns:
- a CallSitereturning the first matching element as described above
- Throws:
- NullPointerException- if any argument is- null
- IllegalArgumentException- if any element in the labels array is null, if the invocation type is not a method type whose first parameter type is an enum type, second parameter of type- intand whose return type is- int, or if- labelscontains an element that is not of type- Stringor- Classof the target enum type.
- 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
 
- as a 
 
-