Hey, I don't suppose anyone could help me out with...
# kodein
d
Hey, I don't suppose anyone could help me out with this issue: https://stackoverflow.com/questions/53408628/how-can-i-create-di-bindings-for-generic-types-in-kotlin TL;DR: need to be able to register
Foo<T>
and resolve
Foo<Int>
or
Foo<String>
.
a
@David Fallah you want to register a
Foo<T>
and retrieve
Foo<Int>
back?
d
@Andreas Sinz I want to register an open generic type to a container like
Foo<>
and be able to resolve
Foo<Int>
,
Foo<String>
or
Foo<T>
for any other sort of
T
that I ask for, by creating an instance of that generic type with the specified type argument(s)
a
Sadly thats not possible on the jvm (maybe you can do it with reflection and unsafe casts) https://stackoverflow.com/a/30647924/4706743
d
The thing is, the Kodein docs say that the "generic" JVM flavour (which I'm using) is immune to type erasure http://kodein.org/Kodein-DI/?6.0/core#_platform_compatibility_genericity
a
that just means that you can bind a
List<Int>
and a
List<Double>
alongside and retrieve one of them based on the generic type, not that you can bind a
List<T>
and create generic instances (e.g.
List<T>
) at runtime
d
Ah, fair enough