0Pricing
Kotlin Academy · Lesson

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

  1. Kotlin Reflection: KClass, KFunction, KProperty
  2. Creating and Targeting Custom Annotations
  3. Reading Annotations at Runtime
  4. Reflection-Based Validation and Mapping
← Back to Kotlin Academy