4 ms·
A minor point on a great article, but "On the other hand, Java’s enum values are really singleton classes under the hood – so one can define an abstract method
by jmgrosen 11y ago
A minor point on a great article, but "On the other hand, Java’s enum values are really singleton classes under the hood – so one can define an abstract method in the enum to implement differently in each value, something that would require a match expression (or hash-table, whose construction at compile time some enterprising Rustaceans have built a crate for) in Rust" isn't quite true -- you can implement methods on enums in Rust, too: http://is.gd/M3VJJR http://is.gd/M3VJJR
- dbaupp 11y agoI suspect the author was talking about defining methods for individual variants of an enum, something like enum Foo { A, B } impl Foo::A { fn method_on_a(&self) {} }
- da4c30ff 11y agoThere is an RFC[1] for making enum variants first-class types. [1]: https://github.com/rust-lang/rfcs/pull/1450 https://github.com/rust-lang/rfcs/pull/1450
- llogiq 11y agoExactly. I must admit that my wording was not as understandable as it should have been. I'll see if I can rephrase it to better convey the point.