Sobes.tech
Junior — Middle

Is it possible to use the refied keyword without inline in the code?

sobes.tech AI

Answer from AI

In Kotlin, the keyword reified is used to obtain type information at runtime in generic functions, but it requires the function to be declared with the inline modifier.

This is because generic types in Kotlin are usually erased during compilation (type erasure), and without inline, it is impossible to get the specific type at runtime.

Therefore, using reified without inline is not allowed — the compiler will produce an error.

An example of correct usage:

inline fun <reified T> isInstance(value: Any): Boolean {
    return value is T
}

If you remove inline, then reified cannot be used.