Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)
Reified Type Parameters (`inline fun <reified T>`): Preserving generic types at runtime.
senior LevelCode ExamplePerformanceTypeScript
In Simple Words:
On the JVM, generics undergo Type Erasure (e.g. List<String> becomes raw List at runtime; T::class.java fails to compile):
reifiedModifier: Combined withinline, the compiler replaces occurrences ofTwith the concrete class type directly at the call site:kotlininline fun <reified T> Gson.fromJson(json: String): T { return fromJson(json, T::class.java) } val user: User = gson.fromJson(jsonString)- Eliminates the need to pass explicit
Class<T>arguments!