3 ms·
They are similar to Kotlin's sealed classes, except there's no concept in Kotlin of an object "consuming" itself, which is necessary for maintaining safety in t
by james-mcelwain 7y ago
They are similar to Kotlin's sealed classes, except there's no concept in Kotlin of an object "consuming" itself, which is necessary for maintaining safety in the API.
For example, in Kotlin, if a method on state A returns state B, there's no way to invalidate all existing references to state A. Normally this invariant would be enforced on the caller's side, or perhaps by throwing an IllegalStateException if state A is called after producing state B.
- Nycto 7y agoAdding to this, I see two other elements that make this tough to replicate in Kotlin: 1. Type erasure 2. Using sealed classes requires instantiation, while the Rust version is zero overhead.
- paulddraper 7y ago> 1. Type erasure There is no need to access type information at runtime here.