How to get actual type arguments of a reified generic parameter in Kotlin?

后端 未结 2 519
无人共我
无人共我 2020-12-03 01:07

Using reified type parameters, one can write an inline function which works with the type parameter through reflection at runtime:

inline fun 

        
2条回答
  •  再見小時候
    2020-12-03 02:03

    If you are using gson library already in the project(for example json parsing). It provides a class for this. com.google.gson.reflect.TypeToken(). So you could use something like,

     f(object : TypeToken>() {}.type)
    
    

提交回复
热议问题