3 ms·
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 f
by Xeamek 3y ago
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.
- kaba0 3y agoRust 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?