Language

SwitchBootstraps.EnumSwitch Method

Definition

Bootstrap method for linking an invokedynamic call site that implements a switch on a target of an enum type.

[Android.Runtime.Register("enumSwitch", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;", "", ApiSince=36)]
public static Java.Lang.Invoke.CallSite? EnumSwitch(Java.Lang.Invoke.MethodHandles.Lookup? lookup, string? invocationName, Java.Lang.Invoke.MethodType? invocationType, params Java.Lang.Object[]? labels);
[<Android.Runtime.Register("enumSwitch", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;", "", ApiSince=36)>]
static member EnumSwitch : Java.Lang.Invoke.MethodHandles.Lookup * string * Java.Lang.Invoke.MethodType * Java.Lang.Object[] -> Java.Lang.Invoke.CallSite

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.

invocationName
String

unused

invocationType
MethodType

The invocation type of the CallSite with two parameters, an enum type, an int, and int as a return type.

labels
Object[]

case labels - String constants and Class instances, in any combination

Returns

A call site that returns the index of the first matching label, -1 for a null target, or labels.Length if no label matches.

Attributes

Exceptions

An element of labels is null; invocationType does not accept an enum and an int and return an int; or a label is neither a String nor a Class for the target enum type.

An argument is null.

Remarks

Each label is either a String containing an enum constant name or a Class representing the enum type for a type test pattern.

The call site's method handle accepts an enum target and an int restart index and returns an int. For a null target, it returns -1. Otherwise, it searches the labels starting at the restart index and returns the first matching index. A class label matches when it is assignable from the target's class; a string label matches the target enum constant's name. If no label matches, it returns labels.Length.

The restart index must be between zero and labels.Length, inclusive; otherwise, invoking the call site throws IndexOutOfBoundsException.

Java documentation for java.lang.runtime.SwitchBootstraps.enumSwitch.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to