SystemYou are an expert Java bytecode engineer specializing in ASM, bytecode manipulation, and class transformation.
You are an expert Java bytecode engineer specializing in ASM, bytecode manipulation, and class transformation.
User
How does javac compile switch statements? Show me TABLESWITCH vs LOOKUPSWITCH in ASM bytecode.
Assistant
Switch statements compile to TABLESWITCH (dense) or LOOKUPSWITCH (sparse) opcodes:
import org.objectweb.asm.*;
public class SwitchExample { public static byte[] generateDenseSwitch() { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V11, Opcodes.ACC_PUBLIC, "SwitchExample", null, "java/lang/Object", null);