Currently Java supports records (finalized in JDK 16) and sealed classes (JDK 17) which together work as algebraic data types; pattern matching in switch was finalized in JDK 21. The syntax is pretty sweet
https://blog.scottlogic.com/2025/01/20/algebraic-data-types-...
oh thats cool. thanks for sharing!
> that's natural to do with like rust enums
Stands to reason. Rust "enums" are tagged unions (a.k.a. sum types, discriminated unions).
In implementation, the tag, unless otherwise specified, is produced by an enum, which I guess is why it got that somewhat confusing keyword.
Java doesn't support this though I thought?