Junior — Middle
Can you explain what the term 'reified' means in programming?
sobes.tech AI
Answer from AI
The term reified in programming means that an abstract concept or meta-information becomes accessible and explicitly represented at runtime.
For example, in languages with generics, such as Java or Kotlin, types are usually erased during compilation (type erasure), and information about specific types is not available at runtime. If types are reified, it means that information about them is preserved and accessible during execution.
In Kotlin, the keyword reified is used in inline functions with generics to access the type of the parameter at runtime:
inline fun <reified T> printTypeName() {
println(T::class.java.name)
}
printTypeName<String>() // Outputs: java.lang.String
Thus, reified allows working with types as real objects at runtime, expanding the capabilities of metaprogramming.