How to pattern match large Scala case classes?

前端 未结 4 2035
攒了一身酷
攒了一身酷 2020-12-05 01:43

Consider the following Scala case class:

case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)

Pattern matching allows me

4条回答
  •  天命终不由人
    2020-12-05 02:47

    You can just specify the type in the matched pattern:

    case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
    
    val someVal = WideLoad(...)
    
    someVal match {
        case w: WideLoad => w.d ! SomeMessage(...)
    }
    

提交回复
热议问题