is there a way to construct an instance of KClass&...
# announcements
d
is there a way to construct an instance of KClass<Foo<Bar>> if all I have is an instance of KClass<Bar>?
And just in case I'm on the wrong track entirely, here's what I want to do
Copy code
fun <T : Any> map(data : SomeData, type: KClass<T>) : Foo<T> = objectMapper.readValue(objectMapper.writeValueAsString(data), my-instance-of-kclass<Foo<type>>)
and then the method would be called with
map(data, Bar::class)
. And of course I could use reified/inline function and then the second argument to readValue would be
Foo<T>
but I want the non-reified version of it 😉
z
KClass<Foo<Bar>>
and
KClass<Bar>
are completely different values -
KClass<Foo<Bar>>
is really just
KClass<Foo<*>>
. KCLasses don't know about type arguments at all, since they are erased at runtime.
KType
is, but needs the full kotlin reflection library for most functionality.
d
I know that they are completely different values. I hoped my example would give an idea of what I'm trying to archive. But I guess I'll just provide
Foo<Bar>
to the method instead of just
Bar
z
I probably misunderstood what you were trying to do. Why the object mapper read/write?
d
The server replies with a json structure that is mapped to
Map<String, Any?>
from the sdk. Then I'm trying to remap it to a more specific (strongly typed properties) dto. But I'm pretty sure I got something wrong in my head. Thanks anyway ;)