如何通过Scala的数组阶可变参数的方法? [英] How pass scala Array into scala vararg method?

查看:240
本文介绍了如何通过Scala的数组阶可变参数的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面一个code:

Consider a code below:

private def test(some:String*){

}

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

它打印预计字符串,发现数组[字符串] 为什么? Scala的可变参数不是数组?哦哦

It prints expect String, found Array[String] Why??? Scala varargs are not array? Oo

注意

我发现在大约阶可变参数计算器几个问题,而是调用Java他们OL可变参数的方法或有关转换斯卡拉列表阵列。它是从code不同。

I found several questions in stackoverflow about scala varargs, but ol of them about calling java varargs methods or about converting scala list to Array. It is differ from that code.

推荐答案

追加:_ * 测试的参数像这样

test(some:_*)

和你期望它应该工作。

And it should work as you expect.

如果你想知道这是什么神奇的:_ * 并请参考的这个问题

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

这篇关于如何通过Scala的数组阶可变参数的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆