Trait, Sealed, and Multiple Inheritance

apaj edited this page Sep 3, 2018 · 1 revision


In Scala, multiple inheritance is implemented using traits, which are similar to abstract classes, except for:

  1. a class can inherit from multiple traits,
  2. a trait can not have constructor parameters.

To inherit multiple traits, the following arrangement is used:

class MyClass extends HasTrait1 with HasTrait2 with ...

A sealed trait can be extended only in the same file as its declaration.


From RocketTiles.scala lines 26-28

class RocketTile(val rocketParams: RocketTileParams, val hartid: Int)(implicit p: Parameters) extends BaseTile(rocketParams)(p)
    with HasLazyRoCC  // implies CanHaveSharedFPU with CanHavePTW with HasHellaCache
    with CanHaveScratchpad { // implies CanHavePTW with HasHellaCache with HasICacheFrontend

From Resources.scala line 9:

sealed trait ResourceValue

Many more examples are given in Mixins

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.