为所有支持 copy(id=newId) 方法的案例类创建共同特征 [英] Create common trait for all case classes supporting copy(id=newId) method

查看:39
本文介绍了为所有支持 copy(id=newId) 方法的案例类创建共同特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做这样的事情:

I'm trying to do something like that:

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

  val id: ObjectId
}

我发现了一些其他相关问题试图做类似的事情,但他们并没有真正回答这个问题.在我的例子中,我试图复制 IdentifiableModel 的 case 类子类,它们都共享一个 id 值

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

推荐答案

Travis Brown 给出了很好的答案,但没有回复.

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

他使用 Scala 宏:如何对方法调用中的命名参数建模Scala 宏?

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

这篇关于为所有支持 copy(id=newId) 方法的案例类创建共同特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆