2012-12-21 23 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 
相关问题