

Writing code using traditional Switch statements is great for low level code. There are a few new features in JEP 354 with the introduction of Switch expressions, but the biggest change is centered around using Switch as an expression instead of a statement. New Features in JEP 354 Switch Expressions Our COVID-19 Developer Impact Report looks at how development professionals and companies have been impacted by the COVID-19 epidemic, and the tactics they are using to stay productive and resilient. Addition as Standard Feature for Java 14Īfter a successful preview stint in JEP 354, Switch Expressions were deemed ready for integration into the language in Java 14 with JEP 361. In JEP 354, OpenJDK developers outlined a few modifications to JEP 325, adding arrow labels and the yield() command. The code below shows it as a Switch expression (with the new -> shorthand.įurther Refinements of Switch Expressions in JEP 354 The above code snippet shows a typical Switch statement trying to act as a switch expression. Throw new IllegalStateException("Wat: " + day) In the examples included on the JEP 325 release (below), they show one such simplification as the motivation for their work. The original intent was to simplify the switch process, as we talk about below. Switch Expressions were first released in JEP 325 as a preview feature. The Introduction of Switch Expressions in JEP 325 That’s not to mention the cumbersome code you get when trying to make Switch statements do things they weren’t designed to do. For example, if you forget to add a break command to one of your blocks, then it and subsequent blocks will be executed until the next applicable break. While switch statements have been with Java since day one, the decision to make them default their control flow to a fall through state makes them hard to troubleshoot.


Switch statements, the precursor to Switch expressions, have been a part of Java since its inception. Switch Expressions, introduced under JEP 325 and refined under JEP 354, are an application of the classic Java switch statement in expression form – which allows developers to yield values.
