如果对象实现了我创建的自定义特征(即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
}