How can I pass the array of class to the below fun...
# android
r
How can I pass the array of class to the below function in Kotlin?
fun <T> convertStringToRequiredArray(stringArrayList: String, clazz: Class<List<T>>): List<T> =
Gson().fromJson(stringArrayList, clazz)
I know in JAVA we can do by this way -->
public <T> List<T> fromJsonAsList(String json, Class<T[]> clazz) {
return Arrays.asList(new Gson().fromJson(json, clazz));
}
List<Book> books = fromJsonAsList(jsonBooksString, Book[].class)
Can anyone please help here?
a
if you need an array then Array<T>. also i can use need to pass kotlin Class or java Class