Joost Klitsie
03/08/2021, 5:02 PMabstract class BaseClient<T> constructor(private val httpClient: HttpClient) {
suspend fun get(): T = httpClient.get<T>("/api/") // T is a reified type: HttpClient.get<reified T>(path: String)
}
Rightly, it will not work and Intellij gives me a warning: Use a class instead! I have the issue, that I cannot pass a class as the httpclient doesn't support that (at least out of the box)
Is there any way I can make this work? Or add some kind of 1 line code I should add/override in the child class that extends from BaseClient?turansky
03/08/2021, 6:08 PMKClass
?
val dataClass: KClass<T> = T::class
suspend fun get(): T =
client.get("/api/", dataClass)
Joost Klitsie
03/08/2021, 6:13 PMturansky
03/08/2021, 7:59 PMHttpResponse
call
TypeInfo
can be constructed from KClass
Joost Klitsie
03/08/2021, 8:18 PM