2012-12-21 43 views
1

假設我有以下代碼:類型不匹配錯誤:發現的SortedSet [INT],需要設置[INT]

case class Foo(x: SortedSet[String]) { 
    def bar: Set[String] = x 
} 

(這是實際的代碼,我的簡化。)如果我嘗試運行這,我得到以下錯誤:

error: type mismatch; 
found : scala.collection.SortedSet[String] 
required: Set[String] 
    def bar: Set[String] = x 

爲什麼我得到這個錯誤?是不是SortedSet[String]減去Set[String]

回答

6

集是immutable.Set。

scala> import scala.collection.immutable.SortedSet 
import scala.collection.immutable.SortedSet 

scala> :paste 
// Entering paste mode (ctrl-D to finish) 

case class Foo(x: SortedSet[String]) { 
    def bar: Set[String] = x 
} 

// Exiting paste mode, now interpreting. 

defined class Foo 
相關問題