Can a single-statement case have a variable declaration as that statement, and what would be its scope?

No, a local variable declaration is a BlockStatement (JLS 14.2), not a Statement (JLS 14.5).  So you could say:

    case FOO -> println(3);

or

    case FOO -> {
        int x = 4;
        println(x);
    }

Of course, you don't have to ask about the scope of x.


Reply via email to