我正在關注Twitter Scala學校教程,並且遇到了一個問題。在隱式視圖部分,在高級類型here下,它聲明方法可以針對某個類型要求特定種類的證據。隱式視圖參數
它列出了這類證據的3 -
A =:= B A must be equal to B
A <:< B A must be a subtype of B
A <%< B A must be viewable as B
不過,我寫的代碼有語法錯誤,當我嘗試第三種。
這是我的代碼
class ContainerTwo[A](value : A) {
// A must be a subtype of Int
def addIt(implicit evidence : A <:< Int) = 123 + value
// A must be a viewable as a String
def printIt(implicit evidence : A <%< String) = println(evidence) // This line reports an error at <%< - "Cannot resolve symbol <%<"
// A must be a subtype of a String
def doSomethingWithAString(implicit evidence : A <:< String) = println(evidence)
}
我使用Scala的2.10。我不確定自己是否做錯了什麼,該教程是錯誤的,還是自編寫教程之後Scala發生了變化。
請始終包含* actual *錯誤,請不要簡單描述爲「報告語法錯誤」。 –