Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/lang/runtime/SwitchBootstraps#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/lang/runtime/SwitchBootstraps#inhmethods)

# SwitchBootstraps

` public class SwitchBootstraps `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.lang.runtime.SwitchBootstraps |

<br />

*** ** * ** ***

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)`.

## Summary

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/lang/invoke/CallSite` | ` https://developer.android.com/reference/java/lang/runtime/SwitchBootstraps#enumSwitch(java.lang.invoke.MethodHandles.Lookup,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Object[])(https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup lookup, https://developer.android.com/reference/java/lang/String invocationName, https://developer.android.com/reference/java/lang/invoke/MethodType invocationType, https://developer.android.com/reference/java/lang/Object labels) ` Bootstrap method for linking an `invokedynamic` call site that implements a `switch` on a target of an enum type. |
| ` static https://developer.android.com/reference/java/lang/invoke/CallSite` | ` https://developer.android.com/reference/java/lang/runtime/SwitchBootstraps#typeSwitch(java.lang.invoke.MethodHandles.Lookup,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Object[])(https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup lookup, https://developer.android.com/reference/java/lang/String invocationName, https://developer.android.com/reference/java/lang/invoke/MethodType invocationType, https://developer.android.com/reference/java/lang/Object labels) ` Bootstrap method for linking an `invokedynamic` call site that implements a `switch` on a target of a reference type. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### enumSwitch

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static CallSite enumSwitch (MethodHandles.Lookup lookup, 
                String invocationName, 
                MethodType invocationType, 
                Object... labels)
```

Bootstrap method for linking an `invokedynamic` call site that implements a `switch` on 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 `String` value, which represents the name of the enum constant associated with the label
- as a `Class` value, which represents the enum type associated with a type test pattern

The returned `CallSite`'s method handle will have a return type of `int` and accepts two parameters: the first argument will be an `Enum` instance (`target`) and the second will be `int` (`restart`).

If the `target` is `null`, then the method of the call site returns -1.

If the `target` is not `null`, then the method of the call site returns the index of the first element in the `labels` array starting from the `restart` index matching one of the following conditions:

- the element is of type `Class` that is assignable from the target's class; or
- the element is of type `String` and equals to the target enum constant's `https://developer.android.com/reference/java/lang/Enum#name()`.

If no element in the `labels` array matches the target, then the method of the call site return the length of the `labels` array.

The value of the `restart` index must be between `0` (inclusive) and the length of the `labels` array (inclusive), both or an `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` is thrown.

<br />

| Parameters ||
|---|---|
| `lookup` | `MethodHandles.Lookup`: Represents a lookup context with the accessibility privileges of the caller. When used with `invokedynamic`, this is stacked automatically by the VM. <br /> |
| `invocationName` | `String`: unused <br /> |
| `invocationType` | `MethodType`: The invocation type of the `CallSite` with two parameters, an enum type, an `int`, and `int` as a return type. <br /> |
| `labels` | `Object`: case labels - `String` constants and `Class` instances, in any combination <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/invoke/CallSite` | a `CallSite` returning the first matching element as described above <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/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 `int` and whose return type is `int`, or if `labels` contains an element that is not of type `String` or `Class` of the target enum type. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if any argument is `null` |

### typeSwitch

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 target of a reference type. The static arguments are an array of case labels which must be non-null and of type `String` or `Integer` or `Class` or `EnumDesc`.

The type of the returned `CallSite`'s method handle will have a return type of `int`. It has two parameters: the first argument will be an `Object` instance (`target`) and the second will be `int` (`restart`).

If the `target` is `null`, then the method of the call site returns -1.

If the `target` is not `null`, then the method of the call site returns the index of the first element in the `labels` array starting from the `restart` index matching one of the following conditions:

- the element is of type `Class` that is assignable from the target's class; or
- the element is of type `String` or `Integer` and 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 `labels` array matches the target, then the method of the call site return the length of the `labels` array.

The value of the `restart` index must be between `0` (inclusive) and the length of the `labels` array (inclusive), both or an `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` is thrown.

<br />

| Parameters ||
|---|---|
| `lookup` | `MethodHandles.Lookup`: Represents a lookup context with the accessibility privileges of the caller. When used with `invokedynamic`, this is stacked automatically by the VM. <br /> |
| `invocationName` | `String`: unused <br /> |
| `invocationType` | `MethodType`: The invocation type of the `CallSite` with two parameters, a reference type, an `int`, and `int` as a return type. <br /> |
| `labels` | `Object`: case labels - `String` and `Integer` constants and `Class` and `EnumDesc` instances, in any combination <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/invoke/CallSite` | a `CallSite` returning the first matching element as described above <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | 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 type `int` and with `int` as its return type, or if `labels` contains an element that is not of type `String`, `Integer`, `Class` or `EnumDesc`. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if any argument is `null` |