How to pass Scala array into Scala vararg method?

后端 未结 2 394
礼貌的吻别
礼貌的吻别 2020-11-29 01:28

Consider the code below:

private def test(some:String*){

}

private def call () {
  val some = Array(\"asd\", \"zxc\")
  test(some)
}

It p

2条回答
  •  旧时难觅i
    2020-11-29 01:49

    Append :_* to the parameter in test like this

    test(some:_*)
    

    And it should work as you expect.

    If you wonder what that magical :_* does, please refer to this question.

提交回复
热议问题