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)”
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.
Popular Pragprog topics










Other popular topics










Latest in Pragprog
Latest (all)
Categories:
My Saved Portals
-
None saved yet
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /preact
- /flutter
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /nim
- /vuejs
- /emacs
- /elm
- /nerves