案例类复制方法的模式匹配

时间:2017-10-11 00:08:24

标签: scala

如果对象实现了我创建的自定义特征(即Status并且拥有案例类提供的copy方法,我想模​​式匹配对象。这可能在Scala中吗?

status match {
  // How to pattern match for copy method support?
  // Is there a common trait we can leverage? or even a structural type construct?
  case s: Status with ???Copy??? => 
    s.copy(status = "NEW")
  case _ =>
    println("No status or no copy support")
    status
}

0 个答案:

没有答案