🐦 Kotlin Intermediate

What is a reified type parameter in Kotlin?

Answer

Due to JVM type erasure, generic type information is lost at runtime — you cannot write obj is T in a generic function. Kotlin's reified keyword, used only with inline functions, preserves the generic type at runtime by inlining the type checks at each call site. inline fun <reified T> isType(obj: Any) = obj is T — the compiler replaces each call with the actual type check (obj is String, obj is Int, etc.). This enables type-safe JSON parsing, dependency injection lookups, and Gson/Retrofit type adapters without passing Class<T> parameters explicitly.