Package Summary Overview Summary

Module java.base
Package java.lang.runtime

# Class SwitchBootstraps

java.lang.Object
java.lang.runtime.SwitchBootstraps

public class SwitchBootstraps extends Object
`SwitchBootstraps` is a preview API of the Java platform.
Programs can only use `SwitchBootstraps` when preview features are enabled.
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)`.

The bootstrap call site accepts a single parameter of the type of the operand of the `switch`, and return an `int` that is the index of the matched `case` label, `-1` if the target is `null`, or `N` if the target is not null but matches no `case` label.

Since:
  17

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static CallSite`
  `typeSwitch​(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels)`
  Bootstrap method for linking an `invokedynamic` call site that implements a `switch` on a reference-typed target.

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### typeSwitch

    public static CallSite typeSwitch​(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) throws Throwable
    Bootstrap method for linking an `invokedynamic` call site that implements a `switch` on a reference-typed target. The static arguments are a varargs array of case labels. Constants and `Class` instances are accepted
    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` - The invocation name, which is ignored. When used with `invokedynamic`, this is provided by the `NameAndType` of the `InvokeDynamic` structure and is stacked automatically by the VM.
      `invocationType` - The invocation type of the `CallSite`. This method type should have a single parameter of a reference type, and return `int`. When used with `invokedynamic`, this is provided by the `NameAndType` of the `InvokeDynamic` structure and is stacked automatically by the VM.
      `labels` - non-null case labels - constants and `Class` instances
    Returns:
      the index into `labels` of the target value, if the target is an instance of any of the types, -1 if the target value is `null`, or `types.length` if the target value is not an instance of any of the types
    Throws:
      `NullPointerException` - if any required argument is null
      `IllegalArgumentException` - if any labels are null, or if the invocation type is not `(T)int for some reference type {@code T}`
      `Throwable` - if there is any error linking the call site