Kotlin converts List<Any> to List<Object>

import com.google.gson.Gson; 

inline fun <reified T> List<Any>.toBeanList(): List<T> {
    
    
        val newList : MutableList<T> = arrayListOf()
        for (item in this){
    
    
            val toJson = gson.toJson( item)
            val entity: T = gson.fromJson(toJson,T::class.java)
            newList.add(entity)
        }
        return newList.toList()
    }

Mainly to record inline and reified, for fear of forgetting, the other is not to read the book too hard, be flexible

Guess you like

Origin blog.csdn.net/shop_and_sleep/article/details/128705712