How to get a generic array out of a generic collection?
I have done the following:
val genericArray: Array<E> = (genericCollection as java.util.Collection<E>).toArray() as Array<E>
Is this the right way to go or is there a more elegant solution?
Looking forward to your help!
EDIT
I ended up writing this helper extension:
fun <E> Collection<E>.toUntypedArray(): Array<E> {
@Suppress("UNCHECKED_CAST")
return arrayOf(size, this) as Array<E>
}
Does anyone of you have a better solution for this problem?