2 ms·
Java enums store the associated data once per option, while Rust enums store it per value. So they're very different. You couldn't model Rust's `Option` or `Res
by CodesInChaos 3y ago
Java enums store the associated data once per option, while Rust enums store it per value. So they're very different. You couldn't model Rust's `Option` or `Result` as a java enum.
- pjmlp 3y agoSure, I didn't say it was the same, only they are more powerful than C, C++ and C#.
- andrybak 3y ago> You couldn't model Rust's `Option` or `Result` as a java enum. For reference, they can be modeled as a "sealed" class since Java 17. https://openjdk.org/jeps/409 https://openjdk.org/jeps/409 Prior to Java 17, sealed classes feature can be partially recreated via private constructors in the super classes. This approach forces you to put all classes in a single Java file, which can be awkward to navigate.