官术网_书友最值得收藏!

How it works...

We have implemented an extension function for the Gson type. Thanks to adding the reified modifier, we can access the generic type argument at runtime and pass it to the original fromGson() function.

As a result, we are able to use the more elegant version of the fromGson() function in our code:

data class ApiResponse(val gifsWithPandas: List<ByteArray>)

val response = Gson().fromJson<ApiResponse>(json)

We could also benefit from Kotlin smart casting and omit the explicit type declaration from the function call:

val response: ApiResponse = Gson().fromJson(json)
主站蜘蛛池模板: 蓬溪县| 杭锦后旗| 新平| 锡林浩特市| 台北县| 资阳市| 文山县| 阿拉尔市| 禹城市| 女性| 桦甸市| 五华县| 施秉县| 新乐市| 深州市| 勃利县| 东阿县| 万年县| 鸡西市| 四平市| 岢岚县| 密云县| 普洱| 嘉鱼县| 茶陵县| 龙口市| 青浦区| 房产| 刚察县| 镇坪县| 尼玛县| 建水县| 临沭县| 安乡县| 黄骅市| 都兰县| 博兴县| 临汾市| 苍梧县| 泽州县| 齐河县|