https://kotlinlang.org logo
#announcements
Title
# announcements
k

Karlo Lozovina

08/20/2020, 6:28 PM
so sealedSubclasses works... now just to instantiate them?
e

ephemient

08/20/2020, 6:57 PM
assuming there's a no-required-args constructor,
Copy code
fun <T : Any> KClass<T>.newInstance(): T = constructors
    .first { it.parameters.all { it.isOptional } }
    .callBy(emptyMap())
or
.java.newInstance()
2 Views