News for hackers. Stuff that matters.
Re:The Grug Brained Developer (2022) by tayo42 on Tuesday June 17, 2025 @09:36PM (#44305855)
OK yeah I see, that's natural to do with like rust enums

Java doesn't support this though I thought?

Re:The Grug Brained Developer (2022) by PaulHoule on Tuesday June 17, 2025 @09:56PM (#44305973)
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-...

Re:The Grug Brained Developer (2022) by tayo42 on Tuesday June 17, 2025 @10:38PM (#44306190)
oh thats cool. thanks for sharing!
Re:The Grug Brained Developer (2022) by 9rx on Wednesday June 18, 2025 @11:20AM (#44310689)
> 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.