3 ms·
So in Rust traits can include full methods bodies, not only signatures?
by EugeneOZ 11y ago
So in Rust traits can include full methods bodies, not only signatures?
- evanpw 11y agoYes: http://rustbyexample.com/trait.html http://rustbyexample.com/trait.html
- pcwalton 11y agoYes. The feature has been proposed for Java too: "defender methods". Originally I resisted them on the grounds of not being necessary, but they're used all over now. Being able to supply a default implementation is extremely useful.
- oldmanjay 11y agoQuick correction: Java 8 does have defender methods.
- EugeneOZ 11y agoThanks to all for explanations! :) And now I think Traits are traits, but can be used as interfaces too :)
- kzrdude 11y agodefault method implementations makes traits behave like mixins, it's very useful (and it is a form of code reuse).
- pcwalton 11y agoTotally agreed. I was wrong to resist them :)
- deleted 11y ago[deleted]
- Manishearth 11y agoThey can also contain associated constants.