Overloading generic event handlers in Scala

后端 未结 2 781
花落未央
花落未央 2021-01-12 13:13

If I define the following generic event handler

trait Handles[E <: Event] {
  def handle(event: E)
}

with event type\'s like this

<
2条回答
  •  庸人自扰
    2021-01-12 13:34

    What's the advantage of two separate handle methods?

    def handle(rawEvent: Event) = rawEvent match {
      case e: InventoryItemCreated => ...
      case e: InventoryItemDeactivated => ...
    }
    

提交回复
热议问题