小编nio*_*cer的帖子

为什么Scala和sbt可以编译这段代码?

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.

scala compilation implicit sbt

2
推荐指数
1
解决办法
84
查看次数

标签 统计

compilation ×1

implicit ×1

sbt ×1

scala ×1