美文网首页Kotlin
Kotlin inline和reified的用法

Kotlin inline和reified的用法

作者: 假装在去天使之城的路上 | 来源:发表于2018-07-09 15:51 被阅读15次

    定义:

        /**convert array response to list */
        private inline fun <reified T : XXXXXResponseInterface>
                parseListFromResponse(jsonArray: JSONArray?): List<T> {
            if (jsonArray == null) {
                return emptyList()
            }
    
            val listType = object : TypeToken<List<T>>() {}.type
    
            return Gson().fromJson(jsonArray.toString(), listType)
        }
    

    用法:

    parseListFromResponse<XXXXXResponseInterface>(jsonArray)
    

    相关文章

      网友评论

        本文标题:Kotlin inline和reified的用法

        本文链接:https://www.haomeiwen.com/subject/kjktpftx.html