From <#C0922A726|general> chanel How about somthi...
# language-proposals
From #general chanel How about somthing like type tokens for reifed type parameters? Use case: serializetion
Copy code
val list: List<String> = listOf("hello", "world")
val out = MyDataOutput(...)
where out.write is something like this:
Copy code
inline fun <reified T: Any> DataOutput.write(obj: T) {
    val type: KType = T::type
    // do something useful with KType and it's type arguments...
The only possible way I can see to do it for now:
Copy code
abstract class TypeToken<T> {}

fun <T: Any> DataOutput.write(obj: T, typeToken: TypeToken) {
    val type = typeToken::class.supertypes[0].arguments[0].type
Copy code
out.write(list, object: TypeToken<List<String>>(){})
For example, gson library use similar aproach