tezvyn:

Explain `inline` and `reified` in Kotlin

Source: kotlinlang.orgadvanced

Tests your grasp of JVM performance costs and type erasure. A great answer explains how `inline` avoids object allocation for lambdas, and how this enables `reified` to bypass type erasure for runtime checks. A red flag is just saying 'it's for performance'.

This question tests your understanding of JVM performance overhead and type erasure. A strong answer first explains that `inline` solves the runtime penalty of higher-order functions by copying the function and lambda bodies to the call site, avoiding object allocation and virtual calls. Then, it connects this to `reified` type parameters, explaining that inlining allows the compiler to know the actual type at the call site, thus bypassing JVM type erasure for runtime checks like `obj is T`.

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 `inline` and `reified` in Kotlin · Tezvyn