forked from ucb-bar/riscv-sodor
-
Notifications
You must be signed in to change notification settings - Fork 21
Trait, Sealed, and Multiple Inheritance
kshalle edited this page Apr 9, 2018
·
1 revision
In Scala, multiple inheritance is implemented using traits
, which are similar to abstract classes, except for:
- a class can inherit from multiple traits,
- 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