地獄Scala專家 - 我需要你的幫助。 我想用類型參數編寫一些泛型函數,但是 類型參數沒有解析。即使簡單的內置類型如String也不能解決。我使用階2.12.1和IntelliJ 2017.1scala類型參數無法解析
我已附加以下
import java.lang.String
trait hello_t
{
def hello_meth1:String
def hello_meth2[T]():T
}
class file_hello extends hello_t
{
// for example String here resolves to java.lang.String
val name:String = "test"
override def hello_meth1 = "hello from method 1"
//But type parameter "String" for hello_meth2 does not resolve - to java.lang.String
// And I get a compilation error see - below
override def hello_meth2[String] = "Hello from method 2"
}
object test extends App
{
val f1 = new file_hello
f1.hello_meth1
f1.hello_meth2
}
/* -- compilation error --
Error:(19, 39) type mismatch;
found : java.lang.String("Hello from method 2")
required: String
override def hello_meth2[String] = "Hello from method 2" ^
*/