Hi, What is the easiest way to convert from `Sort...
# announcements
g
Hi, What is the easiest way to convert from
SortedSet<String>
to pure array
String[]
in Kotlin?
s
Probably
toTypedArray()
g
I tried this one, but it seems do not work in my gradle script.
I think some kind of more “pure” String[]
s
Are you using
.gradle
, or
.gradle.kts
g
gradle.kts
, the related block is:
Copy code
setPublications(publishing.publications.names.toTypedArray() as String[])
And the property publications is defined internally as:
Copy code
String[] publications
s
String[]
isn't a type in Kotlin, and you don't need to cast anything.
toTypedArray
returns
Array<String>
, which is Kotlin's version of
String[]
setPublications(publishing.publications.names.toTypedArray())
g
Yes, I agree, unfortunately this doesn’t work. I receive the following:
Copy code
setPublications(publishing.publications.names.toTypedArray())
                             ^ Type mismatch: inferred type is Array<String!> but String! was expected
s
try adding a * after setPublications(
g
Cool, yes, this did the trick. I was needing the spread operator here
Thanks a lot! 😉
s
No problem :)