Hi, I want to get type of List classifier List<CustomClass>
for example using reflection. How can I achieve this? Is it right using reflection?
I try:
data class Place (
val id: Int,
val destinations: List<String>
)
fun main () {
val aPlace = Place::class
aPlace.memberProperties.forEach { property ->
val propType = property.returnType
val propName = property.name
val propClassName = (propType.classifier as KClass<*>).simpleName
print("""
propertyType = $propType
name = $propName
typeClassName = $propClassName
""")
}
}
The output that i get is:
propertyType = kotlin.collections.List<kotlin.String>
name = destinations
typeClassName = List
propertyType = kotlin.Int
name = id
typeClassName = Int
How to get kotlin.String
in kotlin.collections.List<kotlin.String>
?