简化泛型获取

pull/178/head
hingbong 5 years ago
parent 5a179e1659
commit 2c4aadc4fe
  1. 3
      app/src/main/java/io/legado/app/utils/GsonExtensions.kt

@ -3,7 +3,6 @@ package io.legado.app.utils
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import org.jetbrains.anko.attempt
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
@ -15,7 +14,7 @@ val GSON: Gson by lazy {
.create()
}
inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type
inline fun <reified T> genericType(): Type = T::class.java
@Throws(JsonSyntaxException::class)
inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型

Loading…
Cancel
Save