這是你去哪兒的時候,你是什麼意思,它不能編譯?甚至不能嘗試在Scala中加載一個類
這不是一個修辭問題:什麼是最短或idiomatickest修復?對於獎勵積分,爲什麼有必要?
scala> import scala.util.Try
import scala.util.Try
scala> Try { getClass.getClassLoader loadClass "scala.util.Try" }
我希望這不會給遊戲了,但這裏的消息:
<console>:9: error: type mismatch;
found : Class[_]
required: Class[?0(in value res0)] where type ?0(in value res0)
Note: Any >: ?0, but Java-defined class Class is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10)
Try { getClass.getClassLoader loadClass "scala.util.Try" }
通過「調查」,做他們的意思是像基礎研究,或只適用於已經可用的技術文學?
我還在等待那個結束的錯誤信息,「留給讀者作爲練習。」
更新:
這是Scala 2.10的練習。
像往常一樣,所有的好東西來那些等待:
[email protected]:~/tmp$ skala
Welcome to Scala version 2.11.0-20130622-103744-990c2b024a (OpenJDK 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.language.existentials
import scala.language.existentials
scala> import scala.util.Try
import scala.util.Try
scala> Try { getClass.getClassLoader loadClass "scala.util.Try" }
res0: scala.util.Try[Class[?0]] forSome { type ?0 } = Success(class scala.util.Try)