2017-03-07 231 views
0

我定義了一個Scalatest幫手來比較兩個鞍架這樣的:Scala的類型不匹配

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

但現在我想補充一組列索引的元素,我想跳過測試例如Matlab具有明顯不同的公式來計算偏度比鞍......注意,設置元素類型必須是一樣的幀列索引類型:

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

您的默認參數爲Set()toSkipSet[Nothing]的,你要問Set[CX]類型的Set[CX]()

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