Re:Java 21 makes me like Java again
by Xeamek on Sunday September 17, 2023 @07:20AM
(#37543818)
Is it possible to express Rust enums (tagged unions) and especially the option type in Java? Ofcourse.
But the power of good type system doesn't come from the fact if you can express something, but rather how seamlessly it is integrated in to the language.
[ Parent
| on HN ]
Rust has sum types named wrongly as enums, which java also has as sealed interfaces. The option type is just one example for a sum type, which is as easy to express in Java as
sealed interface Option<T> permits Some<T>, None<T> {
record Some<T>(T value) {}
record None<T>() {}
}
Sure, you have written 3 words more than Rust, and?