Kotlin Reflection: KClass, KFunction, KProperty
Navigate class metadata using KClass and inspect members reflectively.
What Is Reflection?
Reflection lets code inspect and invoke its own structure at runtime: classes, functions, properties, annotations, constructors. Kotlin wraps the JVM reflection API with its own richer types under the kotlin.reflect package.
Getting a KClass
Use ::class on a type or an instance to obtain a KClass reference:
val klass: KClass<String> = String::class
val instance: KClass<out Any> = "hello"::class
println(klass.simpleName) // "String"All lessons in this course
- Kotlin Reflection: KClass, KFunction, KProperty
- Creating and Targeting Custom Annotations
- Reading Annotations at Runtime
- Reflection-Based Validation and Mapping