How to pass Scala array into Scala vararg method?

后端 未结 2 374
礼貌的吻别
礼貌的吻别 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条回答
  • 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.

    0 讨论(0)
  • 2020-11-29 01:50

    It is simple:

    def test(some:String*){}
    
    def call () {
      val some = Array("asd", "zxc")
      test(some: _*)
    }
    
    0 讨论(0)
提交回复
热议问题