Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 500 Bytes

File metadata and controls

29 lines (25 loc) · 500 Bytes

Enums

Switches really shine with enums.

For each case label you need to use the name of the variant, not prefixed with the name of the enum.

enum StopLight {
    RED,
    YELLOW,
    GREEN
}

void main() {
    StopLight light = StopLight.GREEN;
    switch (light) {
        case RED -> {
            IO.println("Stop!");
        }
        case YELLOW -> {
            IO.println("Speed up, coward!");
        }
        case GREEN -> {
            IO.println("Go!");
        }
    }
}