Scala类型在默认参数类型上不匹配

时间:2017-03-07 08:44:48

标签: scala

我定义了一个Scalatest助手来比较两个像这样的Saddle帧:

def compareFrames[RX, CX](result: Frame[RX, CX, Double], expected: Frame[_, _, Double], tol: Double = 1e-10): Unit = {
   // TODO: implement
   ???
}

但是现在我想添加一组我想跳过测试的列索引元素,例如Matlab显然有一个不同的公式来计算Skewness而不是Saddle ...请注意,Set元素类型必须与Frame列索引类型相同:

def compareFrames[RX, CX](result: Frame[RX, CX, Double], expected: Frame[_, _, Double], toSkip: Set[CX] = Set(), tol: Double = 1e-10): Unit = {
   // TODO: implement
   ???
}

但是在调用函数时没有指定默认参数会导致以下编译器错误:

Error:(53, 7) type mismatch;
 found   : scala.collection.immutable.Set[Nothing]
 required: Set[String]
Note: Nothing <: String, but trait Set is invariant in type A.
You may wish to investigate a wildcard type such as `_ <: String`. (SLS 3.2.10)
Error occurred in an application involving default arguments.
      compareFrames(result, expected)

1 个答案:

答案 0 :(得分:1)

final Intent srcIntent = getIntent(); ArrayList<cSportsList> sportsMap = srcIntent.getParcelableExtra("sportsMap"); 的默认参数Set()属于toSkip类型,您必须要求Set[Nothing]类型为Set[CX]()

Set[CX]