Scala案例类复制实现 [英] scala case class copy implementation
本文介绍了Scala案例类复制实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到如何在Scala中为案例类实现复制.
I can't find how copy is implemented for case class in scala.
我可以以某种方式检查它吗?
Can I check it somehow?
我虽然Intellij可以指出我要实现,但是它不想跳转,我也不知道为什么:/
I though Intellij could point me to implementation, but it doesn't want to jump and I have no idea why :/
推荐答案
您可以使用 scalac -print ClassName.scala
作为 copy
检查scala case类的输出.实际上是编译器生成的方法.
You can inspect the scala case class output using scalac -print ClassName.scala
, as the copy
is actually a compiler generated method.
这是一个给定的例子:
case class Test(s: String, i: Int)
这是滤除 copy
的噪声后的输出:
This is the output after filtering out noise for 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();
}
这篇关于Scala案例类复制实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文