snrostov
04/22/2017, 9:48 AMval list: List<String> = listOf("hello", "world")
val out = MyDataOutput(...)
out.write(list)
where out.write is something like this:
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:
abstract class TypeToken<T> {}
fun <T: Any> DataOutput.write(obj: T, typeToken: TypeToken) {
val type = typeToken::class.supertypes[0].arguments[0].type
}
usage:
out.write(list, object: TypeToken<List<String>>(){})
For example, gson library use similar aproach