Just use the super keyword:
trait MemoHashCode { val hashCode = super.hashCode }
This is possible because each attribute implicitly extends AnyRef , which has hashCode . If you want to use methods that are not specific to each object, you will need to make sure that this attribute can only be mixed with objects that have a method that you intend to use. This is possible using self annotations:
trait MemoSomethingElse { this: SomeType => // SomeType has method somethingElse val somethingElse = super.somethingElse }
source share