tezvyn:

Explain Kotlin's `reified` type parameters and their use case

Source: kotlinlang.orgadvanced

Tests your grasp of JVM type erasure and Kotlin's solution. A great answer defines `reified` as making a generic type's Class accessible at runtime, explains this requires an `inline` function to substitute the type at the call site, and shows an example.

This tests your understanding of JVM type erasure and how Kotlin provides a clever workaround. A strong answer first explains that generic types are normally erased at runtime. Then, it introduces `reified` type parameters, which are only available on `inline` functions, as a way to preserve this type information. The key mechanism is that the compiler copies the function's bytecode to the call site, substituting the actual type. This enables runtime checks like `is T` and avoids passing `::class.java` references.

Read the original → kotlinlang.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Explain Kotlin's `reified` type parameters and their use case · Tezvyn