Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Scala数组转换为Java数组的最快方法_Scala - Fatal编程技术网

将Scala数组转换为Java数组的最快方法

将Scala数组转换为Java数组的最快方法,scala,Scala,我在Java中有一个方法,它的签名是void setActiveProfiles(String…profiles),在Java中,我可以向这个方法传递一个字符串数组。我想调用该方法并向其传递一个数组[String],但我得到了类型不匹配错误。我的问题是,将Scala数组转换为Java数组的最佳方式是什么 这是编译错误的主体: type mismatch; found : Array[String] required: String 我找到了答案,并对其进行了测试,调用方法为setAct

我在Java中有一个方法,它的签名是
void setActiveProfiles(String…profiles)
,在Java中,我可以向这个方法传递一个字符串数组。我想调用该方法并向其传递一个
数组[String]
,但我得到了
类型不匹配
错误。我的问题是,将Scala数组转换为Java数组的最佳方式是什么

这是编译错误的主体:

type mismatch;
 found   : Array[String]
 required: String

我找到了答案,并对其进行了测试,调用方法为
setActiveProfiles(array:*)

您是否可以显示错误。你想把Java数组发送到scala函数吗?不,我想用scala中的vararg参数调用Java方法我想我的答案是
setActiveProfiles(数组:*)
你不必做任何事情。如果您有一个java函数,并且它需要一个
String[]
,那么scala编译器本身将
Array[String]
转换为
String[]
。请出示证件error@Jatin否,因为参数类型为vararg。也许您可以更改您的问题以匹配您的答案?