2
如果我們將一個列表傳遞給一個採用可變數量參數的方法,它將起作用。具有可變數量參數的Scala類構造函數
val testList = List("a", "b", "c")
def testMethod(str: String*): Seq[String] = str
testMethod(testList) // outputs WrappedArray(List("a", "b", "c"))
但是,如果我們在一個列表傳遞給類構造函數採用可變數量的參數,我們得到一個類型錯誤。
val testList = List("a", "b", "c")
class TestClass(str: String*)
val t = new TestClass(testList)
// error: type mismatch
// found: List[String]
// required: [String]
任何想法如何解決這個問題?