将 Kotlin 数组转换为 Java 可变参数
Convert Kotlin Array to Java varargs
如何将我的 Kotlin Array
转换为可变参数 Java String[]
?
val angularRoutings =
arrayOf<String>("/language", "/home")
// this doesn't work
web.ignoring().antMatchers(angularRoutings)
How to pass an ArrayList to a varargs method parameter?
有扩展运算符,用*
表示。
展开运算符放在数组参数前面:
antMatchers(*angularRoutings)
有关详细信息,请参阅 documentation:
When we call a vararg
-function, we can pass arguments one-by-one, e.g. asList(1, 2, 3)
, or, if we already have an array and want to pass its contents to the function, we use the spread operator (prefix the array with *
):
请注意,展开运算符只是为数组定义的,不能直接用于列表。处理列表时,使用例如 toTypedArray()
将其转换为数组:
*list.toTypedArray()
如何将我的 Kotlin Array
转换为可变参数 Java String[]
?
val angularRoutings =
arrayOf<String>("/language", "/home")
// this doesn't work
web.ignoring().antMatchers(angularRoutings)
How to pass an ArrayList to a varargs method parameter?
有扩展运算符,用*
表示。
展开运算符放在数组参数前面:
antMatchers(*angularRoutings)
有关详细信息,请参阅 documentation:
When we call a
vararg
-function, we can pass arguments one-by-one, e.g.asList(1, 2, 3)
, or, if we already have an array and want to pass its contents to the function, we use the spread operator (prefix the array with*
):
请注意,展开运算符只是为数组定义的,不能直接用于列表。处理列表时,使用例如 toTypedArray()
将其转换为数组:
*list.toTypedArray()