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 CallSite returning the first matching element as described above

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

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 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 IndexOutOfBoundsException is thrown.

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