Hey, how do I use (non-`reified`) generics with th...
# ktor
r
Hey, how do I use (non-
reified
) generics with the ktor client?
This obviously doesn’t work
Copy code
suspend fun <T> get(url: String): T =
        client.get(url)
e
Hi @ribesg, what kind of
T
do you want to use?
r
I’m using
kotlinx.serialization
, so I guess any data class with the annotation?
e
Could you try
Copy code
suspend fun <T> get(url: String): T =  
        client.get<T>(url)
?
r
Doesn’t change anything, it suggests removing it and I still get
Cannot use 'T' as reified type parameter. Use a class instead.
👀 1
Note that IDEA doesn’t say anything, it’s at compilation time that I get this error (which is weird)
e
It's a bug in IDE: https://youtrack.jetbrains.com/issue/KT-30265. You have to specify
T
explicitly when the parameter can't be reified cause of type erasure.
r
Yes I know that but that doesn’t really help, it means you can’t wrap the ktor client in any class/object. I have to change my plans accordingly. I think I understand why it should not work.
e
You could use
inline
methods with
reified
with
get
like methods. Also you could use
call
or
get<HttpResponse>
explicitly.
Could you provide your project configuration in ticket https://youtrack.jetbrains.com/issue/KT-30265#comment=27-3322624 ?