Why inline classes does not support generic types?
# announcements
s
Why inline classes does not support generic types?
r
Because it’s not a real class. Think about what an
inline class
is for a minute. Try to find how generics could work with that
s
I don’t know why, but this can be a ‘workaround’:
Copy code
inline class Wrap<T>(private val _value : Any?) {
    val value : T get() = _value as T    
}
m
I suspect that if you do that, you lose any benefit an inline class might provide as the compiler won’t ever be able to inline. Plus the other intent of inline classes is to provide Stronger typing around common types. What is the value of using Wrap versus just defining your variable as whatever T is? I think you should review what inline classes do, and why they exist.
👍 6
s
^^^ Good point
i
Currently generic value type in inline classes is not supported because it's unclear how exactly to represent such inlined value. See the options in https://github.com/Kotlin/KEEP/blob/master/proposals/inline-classes.md#generic-inline-class-mapping