Scala工作表的示例
case class Test(name: String)
case class TestMapped(name: String,
otherProperty: String)
protected implicit def toTestMapped(test: Test): TestMapped = {
TestMapped(name = test.name,
otherProperty = test.otherProperty)
}
val test = Test(name = "bug")
val testMapped = toTestMapped(test)
Run Code Online (Sandbox Code Playgroud)
如果在类Test中不存在"otherProperty",为什么Scala和sbt可以编译这段代码?此代码以关键运行时错误结束:java.lang.StackOverflowError
但是,如果删除toTestMapped方法的"隐式",或者通过其他名称更改"otherProperty",则此代码不会编译.
我正在使用Scala 2.12.4.