only classes are allowed on the left hand side of a class literal

女生的网名这么多〃 提交于 2019-12-03 06:12:37

You can't use generics with class, as easily observable here:

List<Int>::class.java

It gives you the same error. To use the generic typ in GSON deserialization, do what is suggested here:

https://stackoverflow.com/a/5554296/8073652

EDIT:

In Kotlin it looks like this:

val type: Type = object : TypeToken<ServiceCall<SurveyListModel>>() {}.type 
Gson().fromJson<ServiceCall<SurveyListModel>>(json, type).result

Here's a small proof of concept, I've written:

 class Token : TypeToken<List<Int>>()
 val x: List<Int> = Gson().fromJson(Gson().toJson(arrayOf(1)), Token().type)
 println(x)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!