1
我試圖寫一些簡單的方法toList
...簡單的類型不匹配錯誤
trait Stream[+A] {
def uncons: Option[(A, Stream[A])]
def isEmpty: Boolean = uncons.isEmpty
def toList[A]: List[A] = this.uncons match {
case Some((h,t)) => h::t.toList
case None => List()
}
}
然而,這將導致以下錯誤:
type mismatch; found : x$1.type (with underlying type A) required: A
我不明白爲什麼這個代碼不起作用。也許我失去了一些東西很明顯:(
啊...非常感謝,愚蠢的錯誤:) – Maciej