Functional Programming in Java, Second Edition: Chapter 10 "Error Handling", p.175

We read:

We are using the amazing feature of the switch expression of Java [Java 12]. If you’re using an older version of Java, you may use the traditional if-else instead— the code will be a tad verbose but will get the job done.

Remark 1

The new switch gets a bit of a short shrift. Maybe this paragraph should be extended a bit. It should at least refer to further sources, namely:

https://blogs.oracle.com/javamagazine/post/new-switch-expressions-in-java-12

Some more:

Remark 2

I later noticed that this is actually a “pattern matching” feature of the switch as described in “JEP406: Pattern Matching for switch (Preview)”

https://openjdk.org/jeps/406

It has been in preview since “Release 17” (September 2021) and still is in preview in Java 18. The “Java of the book” is Java 18, so can we really use it? One should indicate that “it has been in preview since Java 17, September 2021 and is still in preview for Java 18” at least.