July 2018
Intermediate to advanced
242 pages
8h 6m
English
While implementing functions that support generic type arguments, we often deal with the need to provide additional information about object types at runtime. On the JVM platform, types have their representations in the Class<T> class instances. For example, we can face such a need while parsing JSON formatted data to the Kotlin class instances using the Gson library:
data class ApiResponse(val gifsWithPandas: List<ByteArray>)data class Error(val message: String)fun parseJsonResponse(json: String): ApiResponse { Gson().fromJson(json, ApiResponse::class.java)}
Normally, we can't access the generic type argument at runtime because of a JVM types erasure. However, Kotlin allows you to overcome ...
Read now
Unlock full access