Skip to content

Commit 9a58b77

Browse files
author
fankarl
committed
添加字符串转换内联函数写法(待测试)
1 parent 83c00d6 commit 9a58b77

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/src/main/java/com/xiasuhuei321/gank_kotlin/extension/JsonExtension.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ fun <T> jsonToList(json:String):ArrayList<T>{
2727
val type = object:TypeToken<ArrayList<T>>(){}
2828
return GsonBuilder().create().fromJson<ArrayList<T>>(json,type.type)
2929
}
30-
fun <K,T> jsonToMap(json: String):Map<K,T>{
31-
val type = object : TypeToken<Map<K,T>>(){}
32-
return GsonBuilder().create().fromJson(json,type.type)
30+
31+
/**
32+
* 内联函数
33+
*/
34+
inline fun <reified T:Any> json2List(json:String):MutableList<T>{
35+
val subType = TypeToken.getParameterized(MutableList::class.java,T::class.java)
36+
return GsonBuilder().create().fromJson(json,subType.type)
3337
}

0 commit comments

Comments
 (0)