Or, for the case of errors, with exceptions, which happen to have their own very limited pattern matching syntax.
I swear I am not paid to shill for Java or anything…, but Java did get sum types recently, and it’s quite good. They made it in a backwards compatible manner by sealed classes that list all of its subtypes.
Switch expressions were also implemented, and they can exhaustively match on the given sum type. Pattern matching is quite limited as of now (only usable with records), but it is coming.
Re:Switching from C++ to Rust
by cmrdporcupine on Tuesday March 14, 2023 @07:43AM
(#35149977)
I should take a look. I kind of have a nostalgic interest in looking back at the JVM again, as 10 years ago it was my main career.
The problem with Java was always that it has moved so slowly in acquiring nice things. The actual core runtime is amazingly well engineered.
Enums + switch is the other, and far less powerful.