Convert Kotlin Array to Java varargs

后端 未结 1 1260
清歌不尽
清歌不尽 2020-12-07 21:46

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

val angularRoutings = 
    arrayOf(\"/language\", \"/ho         


        
相关标签:
1条回答
  • 2020-12-07 22:05

    There’s the spread operator which is denoted by *.
    The spread operator is placed in front of the array argument:

    antMatchers(*angularRoutings)
    

    For further information, see the 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 *):

    Please note that the spread operator is only defined for arrays, and cannot be used on a list directly. When dealing with a list, use e.g.toTypedArray() to transform it to an array:

     *list.toTypedArray()
    
    0 讨论(0)
提交回复
热议问题