现在我不是假装这段代码是好的编程习惯,但我不明白为什么它不会编译。这里发生了什么?
object CustomTo extends App {
val thing:Something = new Something
val str:String = thing.to[String]
println(str)
}
class Something {
def to[String]:String = {
"hello"
}
}
编译器输出:
CustomTo.scala:9: error: type mismatch;
found : java.lang.String("hello")
required: String
"hello"
^
one error found