Kotlin Reified Types in Inline Functions

Kotlin Reified Types in Inline Functions

Functional Programming, Kotlin, Software Development, Tutorial
Kotlin Reified Types in Inline Functions I've noticed that many people haven't ever heard of reified types or have problems understanding what they are and what they do. Therefore this little post is intended to bring some light into the darkness of Kotlin's reified types. Starting situation fun <T> myGenericFun(c: Class<T>) In an ordinary generic function like myGenericFun, you can't access the type T because it is, like in Java, erased at runtime and thus only available at compile time. Therefore, if you want to use the generic type as a normal Class in the function body you need to explicitly pass the class as a parameter like the parameter c in the above example. That's correct and works fine but makes it a bit unsightly for the caller. Inlined…
Read More