Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!