Marc Knaup
05/28/2020, 10:07 AMopen class Generic<T: Any> private constructor(
private val type: KType
) {
inline <reified T> constructor():
this(type = typeOf<T>())
}
Does anyone else have good use cases for this?Marc Knaup
05/28/2020, 10:07 AMspand
05/28/2020, 10:13 AMMarc Knaup
05/28/2020, 10:14 AMMarc Knaup
05/28/2020, 10:14 AMclass SomeClass: Generic<List<String?>>()
drieks
05/29/2020, 6:33 AM@Suppress("FunctionName")
inline fun <reified T> SomeClass(): SomeClass<T>() {
return SomeClass(typeOf<T>())
}
class SomeClass<T>(val type: KType)
(I see you already mentioned it before in the ticket)Marc Knaup
05/29/2020, 6:43 AMobject
, so that workaround won’t work.
My current workaround is that each object
has to call an extension function during initialization which allows me to generate a KType
efemoney
06/03/2020, 12:27 AMfun constructor(): SomeClass {...}
that generates a ‘static’ (or top level in kotlin terms) function with same name as class. Should be possible to make it inline and have reified type params