Package Summary  Overview Summary

class:SwitchBootstraps [CHANGED]


public class SwitchBootstrapsextends 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

public class SwitchBootstrapsextends 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

public class SwitchBootstrapsextends 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).
Since:
17

method:typeSwitch(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.invoke.MethodType,java.lang.Object...) [CHANGED]

  • 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 target of a reference -typed targettype. The static arguments are a varargsan array of case labels . Constantswhich must be non-null and of type String or Integer or Class.

    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 instances are acceptedthat is assignable from the target's class; or
    • the element is of type String or Integer and 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.

    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.unused
    invocationType - The invocation type of the CallSite . This method type should havewith two parameters, a single parameter of areference type, an int, and int as a return int. When used with invokedynamic, this is provided by the NameAndType of the InvokeDynamic structure and is stacked automatically by the VMtype.
    labels - non-nullcase labels - String and Integer constants and Class instances, in any combination
    Returns:
    a CallSite , which accepts two parameters: one is an instance ofreturning the target type, and second is a restart index. It returns the index into labels of the target value, if the target is an instance of any of the types or equal to any of the constants, -1 if the target value is null, or types.length if the target value is not an instance of any of the types or equal to any of the constants. Will return an index that is greater or equal to the restart index provided.first matching element as described above
    Throws:
    NullPointerException - if any requiredargument is null
    IllegalArgumentException - if any element in the labels arearray is null, orif the invocation type is not (T)not a method type of first parameter of a reference type, second parameter of type int and with int for some reference as its return type, or if labels contains an element that is not of type {@code T}String , Integer or Class.
    Throwable - if there is any error linking the call site
    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
  • 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 of type String or Integer 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 - String and Integer constants and Class instances, in any combination
    Returns:
    a CallSite, which accepts two parameters: one is an instance of the target type, and second is a restart index. It returns the index into labels of the target value, if the target is an instance of any of the types or equal to any of the constants, -1 if the target value is null, or types.length if the target value is not an instance of any of the types or equal to any of the constants. Will return an index that is greater or equal to the restart index provided.
    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
  • 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 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.

    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.

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

    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 CallSite with two parameters, a reference type, an int, and int as a return type.
    labels - case labels - String and Integer constants and Class instances, in any combination
    Returns:
    a CallSite returning 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 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 or Class.
    Throwable - if there is any error linking the call site
    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