https://kotlinlang.org logo
Title
p

poohbar

11/29/2017, 1:18 PM
I am not an expert on generics and I like that we can reify generics in case of inline functions. Why can't Kotlin reify all other generics as well though? Just fake it by passing an extra parameter of type Class to any generic method?
d

diesieben07

11/29/2017, 1:22 PM
Because that would both have quite the runtime overhead and also make interoperability with Java a huge pain, since this reification behavior is no longer opt-in. Moreover a
Class
alone is not enough in some cases, as you might use the type parameter to create an anonymous inner class with that type parameter (i.e. when constructing a
TypeToken
from guava), which then requires the full type, not just the raw class. Another point is that
Class
is JVM specific.
p

poohbar

11/29/2017, 2:35 PM
Thanks a lot!