Let's assume that we have a common trait Model.
trait Model {
def id: String
def updated: Date
}
And we have 2 case classes extending this trait.
case class C1(id: String, updated: Date, foo: String) extends Model
case class C2(id: String, updated: Date, bar: Int) extends Model
Is it possible to write a utility function like below which takes a Model as parameter and returns a copy with an updated value for the updated field?
object Model {
def update[T <: Model](model: T): T = {
model.copy(updated = new Date) // This code does not compile.
}
}