Robert Menke
08/20/2019, 8:40 PMinline
?simon.vergauwen
08/20/2019, 8:51 PMreified
generics on the JVM so the compiler inlines the generic param.
i.e. inline fun <reified A> fromJson(json: String) = Gson().fromJson(json, A::class.java)
when called as fromJson<Person>(json)
the compiler simply turns it into Gson().fromJson(json, Person::class.java)
.
So you could call it reifying generics by inlining.jw
08/20/2019, 8:55 PMreified
just means that the type parameter is resolvable at compile-time. you don't need inline
for this, the compiler could rewrite the signature to accept a KClass, for example, and synthesize it at the callsite.jw
08/20/2019, 8:56 PMinline
is just the current implementation where the function body is copy/pasted and the type parameters which are guaranteed to be resolvable to a class at compile-time are replaced with references to said resoled classRobert Menke
08/21/2019, 12:57 AMGotcha I kind of assumed as much I just didn’t know if there was some underlying reason I was missingis just the current implementationinline
simon.vergauwen
08/21/2019, 6:28 AMDerek Berner
08/30/2019, 4:56 PMthe compiler could rewrite the signature to accept a KClass, for example, and synthesize it at the callsite.Why isn't this the way the Kotlin compiler does it?
Derek Berner
08/30/2019, 4:58 PMDerek Berner
08/30/2019, 4:59 PM