3 ms·
OK yeah I see, that's natural to do with like rust enums Java doesn't support this though I thought?
by tayo42 1y ago
OK yeah I see, that's natural to do with like rust enums
Java doesn't support this though I thought?
- PaulHoule 1y agoCurrently 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-with-java.html https://blog.scottlogic.com/2025/01/20/algebraic-data-types-...
- tayo42 1y agooh thats cool. thanks for sharing!
- 9rx 1y ago> 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.