鉴于此代码:
object Testy extends App {
case class Person(
id: Option[Long],
firstName: String,
lastName: String,
address: Address)
case class Address(id: Option[Long],
name: String,
number: Int)
val personOrAddress:AnyRef= Person(Some(1L), "first", "last", Address(Some(1L), "street", 1))
type HasCopyMethodWithId = _
val newId = Some(123L)
personOrAddress.asInstanceOf[HasCopyMethodWithId].copy(id = newId)
}
如何实现'type HasCopyMethodWithId',以便此代码编译并且在运行时不会失败?
我试过了:
type HasCopyMethodWithId = {def copy(id: Option[Long]): AnyRef}