Hi all! I have a question about reified function c...
# ktor
j
Hi all! I have a question about reified function calls from abstract classes:
Copy code
abstract 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?
t
What about using
KClass
?
Copy code
val dataClass: KClass<T> = T::class

suspend fun get(): T = 
    client.get("/api/", dataClass)
j
Does that method exist in the ktor library? I couldn't find it :(
t
Screen Shot 2021-03-08 at 10.59.16 PM.png
You can receive
HttpResponse
And then use it
call
TypeInfo
can be constructed from
KClass
j
Thanks for the effort! I might just copy/paste the builder methods and then indeed add the kclass parameter, but it would be annoying to maintain :) I made now some easy pattern that shouldn't require too much code in the implementing classes