APIdia Launch Partner
Top Description Methods
java.lang.classfile.instruction

public sealed Interface TableSwitchInstruction

extends Instruction
permits BoundTableSwitchInstruction, UnboundTableSwitchInstruction
Known Direct Implementers
jdk.internal.classfile.impl.AbstractInstruction.BoundTableSwitchInstruction, jdk.internal.classfile.impl.AbstractInstruction.UnboundTableSwitchInstruction
Imports
java.lang.classfile.CodeBuilder, .CodeElement, .CodeModel, .Instruction, .Label, .Opcode, java.util.List, jdk.internal.classfile.impl.AbstractInstruction

Models a tableswitch instruction in the code array of a Code attribute. Delivered as a CodeElement when traversing the elements of a CodeModel.

A table switch instruction is composite:

TableSwitchInstruction( int lowValue, int highValue, Label defaultTarget, List<SwitchCase> cases )
TableSwitchInstruction(
    int lowValue,
    int highValue,
    Label defaultTarget,
    List<SwitchCase> cases
)

When read from class files, the cases may omit cases that duplicate the default target. The list is sorted ascending by the caseValue.

When writing to class file, the order in the cases list does not matter, as there is only one valid order in the physical representation of table switch entries. Treatment of elements in cases whose value is less than lowValue or greater than highValue, and elements whose value duplicates that of another, is not specified.

Since
24
Java Virtual Machine Specification
6.5.tableswitch tableswitch
See Also
Opcode.Kind#TABLE_SWITCH, CodeBuilder::tableswitch

Method Summary

Modifier and TypeMethod and Description
public List<SwitchCase>

Returns:

the cases of the switch
cases
()

Returns the cases of the switch.

public Label

Returns:

the default target of the switch
defaultTarget
()

Returns the default target of the switch.

public int

Returns:

the high value of the switch target range, inclusive
highValue
()

Returns the high value of the switch target range, inclusive.

public int

Returns:

the low value of the switch target range, inclusive
lowValue
()

Returns the low value of the switch target range, inclusive.

public static TableSwitchInstruction

Returns:

a table switch instruction
of
(int
the low value of the switch target range, inclusive
lowValue
,
int
the high value of the switch target range, inclusive
highValue
,
Label
the default target of the switch
defaultTarget
,
List<SwitchCase>
the cases of the switch; duplicate or out of bound case handling is not specified
cases
)

Returns a table switch instruction.

Inherited from java.lang.classfile.Instruction:
opcodesizeInBytes

Method Detail

casesback to summary
public List<SwitchCase> cases()

Returns the cases of the switch.

Returns:List<SwitchCase>

the cases of the switch

defaultTargetback to summary
public Label defaultTarget()

Returns the default target of the switch.

Returns:Label

the default target of the switch

highValueback to summary
public int highValue()

Returns the high value of the switch target range, inclusive.

Returns:int

the high value of the switch target range, inclusive

lowValueback to summary
public int lowValue()

Returns the low value of the switch target range, inclusive.

Returns:int

the low value of the switch target range, inclusive

ofback to summary
public static TableSwitchInstruction of(int lowValue, int highValue, Label defaultTarget, List<SwitchCase> cases)

Returns a table switch instruction.

Parameters
lowValue:int

the low value of the switch target range, inclusive

highValue:int

the high value of the switch target range, inclusive

defaultTarget:Label

the default target of the switch

cases:List<SwitchCase>

the cases of the switch; duplicate or out of bound case handling is not specified

Returns:TableSwitchInstruction

a table switch instruction

Exceptions
IllegalArgumentException:
if the low value is greater than the high value, or if there are too many targets between the low and high values