[switch] Further unification on switch

Brian Goetz brian.goetz at oracle.com
Thu Apr 19 22:27:06 UTC 2018


>
> 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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180419/029d3a2e/attachment.html>


More information about the amber-spec-experts mailing list