What is a reified type parameter in Kotlin?

Tests JVM type erasure and inline function mechanics. Strong answer: reified preserves generic types at runtime via inline expansion, enabling is T checks without Class<T> passing. Red flag: claiming reified works without inline or outside functions.
What's really being asked
This tests whether you understand JVM type erasure and how Kotlin's inline machinery bypasses it at compile time. Senior engineers should know why you cannot normally write is T or reference T::class inside a generic function, and how reified changes the bytecode generation story so the concrete type survives at the call site.
The full answer
First, explain type erasure: on the JVM, generic type parameters like T are erased to Object or their bound at runtime, so foo<T>() has no access to T after compilation. Second, explain inline functions: the compiler copies the function body into every call site, which means the concrete type argument is known during that inlining pass. Third, explain the reified keyword: marking a type parameter as reified tells the compiler to substitute the actual type into the inlined body, making T available at runtime in that specific call site. Fourth, give the practical payoff: you can write is T, T::class, and type checks without passing Class<T> objects or using reflection.
The mistakes people make
A red flag is claiming reified works on regular non-inline functions or inside classes as members. Another is saying it is just compiler sugar for passing MyClass::class.java automatically; while similar in effect, the mechanism is bytecode substitution at the call site, not reflection. Also, watch out for saying reified eliminates type erasure globally; it only works per call site of an inline function.
What usually comes next
An interviewer might ask about the cost: inlining increases bytecode size, so reified utilities should stay small and focused. They might ask where reified fails: it cannot be used with class members, only top-level or local functions, because the JVM cannot inline across virtual dispatch. They might also ask how this compares to Java's Class<T> pattern or to using instanceof directly.
A concrete example
The canonical example from the documentation is a tree traversal where you want findParentOfType<MyNodeType>(). Without reified, you must declare fun <T> findParentOfType(clazz: Class<T>) and call it with MyNodeType::class.java, then use clazz.isInstance inside a loop. With reified, you write inline fun <reified T> findParentOfType(): T? and use p !is T directly at the call site. The compiler inlines the function and replaces T with MyNodeType, emitting a real instanceof check in the generated bytecode.
Interview question
Why can a reified type parameter be checked with is T at runtime despite JVM type erasure?
- a.The compiler passes the type's Class object implicitly as a hidden parameter.
- b.Type erasure is globally disabled for functions declared with the reified modifier.
- c.The compiler substitutes the concrete type into the inlined body at each call site.Correct
- d.The JVM retains generic type metadata specifically for reified parameters.
Why? this is the answer
Inline expansion lets the compiler replace T with the concrete type at the call site, emitting a real instanceof check. Option A is tempting but wrong because reified does not rely on reflection or pass a Class object; it works by bytecode substitution during compilation.
Just read this? Test yourself on what you have been reading.
Read the original → kotlinlang.org
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on kotlin — each one lists the topics its interview covers.
See open roles