Switch syntax; pedagogical nightmare?

Brian Goetz brian.goetz at oracle.com
Thu Aug 3 13:43:05 UTC 2017

> I just watched the Java One talk by Brien, and can't help but feel that
> overloading the 'switch' keyword for pattern matching is a hell of a
> mistake. I realize the appeal in that it doesn't introduce a new keyword
> due to backwards source compatibility, but feel like it's a pedagogical
> nightmare.
> Having the break;s left off is clearly desirable for pattern matching that
> involves destructing, but you are going to be leading so many newbies to
> using switch statements (as opposed to expressions) without break,
> expecting it to behave similar to the new expression usage of switch.

I think you have misinterpreted what is being proposed.  Statement switch with patterns has exactly the same control flow behavior as it does without patterns — there is no relationship between whether the case labels are patterns and the break/fallthrough behavior.  

Similarly, if we introduce a switch *expression* (whose syntax would differ from statement switch), again this has nothing to do with patterns; it will behave the same way with patterns and without.  

So, the sky is not falling ;)

More information about the amber-dev mailing list