このコードが優れたプログラミング手法であると主張しているわけではありませんが、コンパイルできない理由がわかりません。何が起きてる?
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