Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So in Rust traits can include full methods bodies, not only signatures?


Yes. 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.


Quick correction: Java 8 does have defender methods.


default method implementations makes traits behave like mixins, it's very useful (and it is a form of code reuse).


Totally agreed. I was wrong to resist them :)


Thanks to all for explanations! :) And now I think Traits are traits, but can be used as interfaces too :)



They can also contain associated constants.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: