Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Why to use 'inline' when using a 'reified' type

All the tutorials I read about type reification say that we need to use 'inline' when using 'reified', but none of them explain why.

Let's say I have a function:

inline fun <reified T> doSomething(value: T) {
    println("Doing something with type: ${T::class.simpleName}")    
}

As far as I understand, using 'reified' prevents type erasure. So why can't we make use of it in a normal non-inlined function. Using inlined is going to make the compiler copy the body of the above function at the call sites. But why do we need that to happen?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Reified types are not magic - type erasure still happens as usual. So how does reified types work? Well, let's say I call:

doSomething("Foo")

The compiler works out that T is String. And it can directly translate the above line into:

println("Doing something with type: ${String::class.simpleName}")

Therefore, at a surface level, it looks like as if the type is reified, but in actuality, the type is just inlined. This is also why the function needs to be inline. If it is not inline, the compiler cannot inline the type parameter.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda