Proguard is ruining my cleanliness. Gson and generics
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a function that loads information from persistence, and I just tell the type it is in a really simple way. The class is called SharedPreferencesHelper.kt so it is a really life problem solver: fun <T> loadList(context: Context, fileName: String, key: String, defValue: ArrayList<T>) : ArrayList<T> { val gson = MyGsonDependency.getInstance() val json = getWithFileName(context, fileName).getString(key, gson.toJson(defValue)) return gson.fromJson(json, object : TypeToken<ArrayList<T>>() {}.type) } to load, for example, an ArrayList<String