https://kotlinlang.org logo
#reflect
Title
# reflect
v

v79

12/05/2018, 9:03 PM
I'm trying to load some classes dynamically at runtime, which should all implement a specific interface,
GeneratorPipeline
. Given a String array of class names, I'd like the corresponding array of KClass objects. But this fails on line 7
processorPipeline.add(kClass)
as
kClass
is of type
KClass<out Any!>
. Any ideas? Loosening the array
processorPipeline = arrayListOf<KClass<*>>()
is OK, but ultimately I need
Array<KClass<GeneratorPipeline>>
It got a bit easier when I switched to using
ArrayList<KClass<GeneratorPipeline>>
instead of a plain Array... But I still have to define the
processorPipeline
as
ArrayList<KClass<*>>
and then create second ArrayList as
ArrayList<KClass<GeneratorPipeline>>
, with an Unchecked Cast warning.