Given this code:
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)
}
How can I implement 'type HasCopyMethodWithId' so that this code compiles and does not fail in runtime?
I've tried:
type HasCopyMethodWithId = {def copy(id: Option[Long]): AnyRef}
copyIdthat would use copy. - Ćukasz