Scala:Trait
lastmod 2020-08-26created 2020-08-261 edits
Traits are used to share interfaces and fields between classes.
They are similar to Java 8's interfaces. Classes and objects can extend traits, but traits cannot be instantiated and therefore have no parameters.
Defining a trait
A minimal trait is simply the keyword trait and an identifier:
Traits become especially useful as generic types and with abstract methods.
See also
- trait