David came across some Java code. This particular block needed to, based on an integer masquerading as an enumerated type, return an amount of time to sleep. It has strong opinions about what should happen when you send it an invalid value:

private static int getTime(int mode) {
    return switch (mode) {
        case 0 -> 30 * SECOND;
        case 1 -> 15 * SECOND;
        case 2 -> 10 * SECOND;
        case 3 -> 20 * SECOND;
        case 4 -> 17 * SECOND;
        case 5 -> 32 * SECOND;
        default ->
            // go to hell
            1000000000;
    };
}

Now, actually using an enum wouldn't solve this, though it'd make the code more clear. There's always the risk that the enum would have values added, and then you'd need to update the switch. Besides, maybe enums were just too new- they were only added in 2004 after all. The switch expression syntax here was added in 2020, however, so…

I just have to wonder: why not just use Integer.MAX_VALUE? If you want to send them to hell, why not really send them to hell?

[Advertisement] Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.