With the help of reified
keyword, we can now access generic type without explicitly passing the class as a pararmeter.
Without reified
:
fun <T: Any> String.toObject(c: KClass<T>): T {
return Gson().fromJson(this, c.java)
}
val jsonObject = jsonString.toObject(JsonObject::class.java)