Kotlin:将数组转换为Java varargs [英] Kotlin: Convert Array to Java varargs

查看:1207
本文介绍了Kotlin:将数组转换为Java varargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的Kotlin 数组转换为varargs Java String []

How can I convert my Kotlin Array to a varargs Java String[]?

val angularRoutings = 
    arrayOf<String>("/language", "/home")

// this doesn't work        
web.ignoring().antMatchers(angularRoutings)

如何将ArrayList传递给varargs方法参数?

推荐答案

您应该使用传播运算符,如下所示: *
扩展运算符需要以数组参数为前缀:

You should use the "spread operator", which looks like this: *
The spread operator needs to be prefixed to the array argument:

antMatchers(*angularRoutings)

有关详细信息,请参阅 documentation

For further information, see the documentation:


W如果我们称之为 vararg -function,我们可以逐个传递参数,例如: asList(1,2,3),或者,如果我们已经有一个数组并希望将其内容传递给函数,我们使用spread运算符(数组前缀为 * ):

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 *):

这篇关于Kotlin:将数组转换为Java varargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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