我找不到scala中case class的复制实现方式。
我能以某种方式进行检查吗?
我原本认为Intellij可以指向实现,但它不想跳转,我不知道为什么 :/
scalac -print ClassName.scala
来检查 Scala case class 的输出,因为 copy
实际上是由编译器生成的方法。case class Test(s: String, i: Int)
copy
的输出结果:case class Test extends Object with Product with Serializable {
private[this] val s: String = _;
def s(): String = Test.this.s;
private[this] val i: Int = _;
def i(): Int = Test.this.i;
def copy(s: String, i: Int): common.Test = new common.Test(s, i);
def copy$default$1(): String = Test.this.s();
def copy$default$2(): Int = Test.this.i();
}
Test("a",3).copy(i=5)
,我仍然不确定会调用什么。 - kpbochenekdef copy(s: String, i: Int): common.Test = new common.Test(s, i);
- Yuval Itzchakov