Create common trait for all case classes supporting copy(id=newId) method

浪尽此生 提交于 2019-12-09 16:48:27

问题


I'm trying to do something like that:

trait IdentifiableModel[T] {
  self: { def copy(id: ObjectId): T } =>

  val id: ObjectId
}

I've found some other related questions trying to do similar things but they didn't really answer to this question. In my case, I'm trying to copy the case class subclasses of IdentifiableModel that all share an id value


回答1:


Travis Brown has the good answer but didn't reply.

He uses Scala macros: Howto model named parameters in method invocations with Scala macros?



来源:https://stackoverflow.com/questions/15078102/create-common-trait-for-all-case-classes-supporting-copyid-newid-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!