dimanche 5 août 2018

How to set type of a class using local variable that holds that type?

I've got a method that does the following:

 val type = AClass::class.java.methods[0].parameters[0].type
 val toDeserialise = SecondClass<type>()

My SecondClass is:

class SecondClass<T : Any> {
    lateinit var p1: T
}

But this doesn't work. Basically, I want to take a type of a method's parameter and pass it into a SecondClass. Do you know how to implement this?





Aucun commentaire:

Enregistrer un commentaire