https://kotlinlang.org logo
Title
u

user

06/20/2022, 4:21 AM
Set type of a variable dynamically in kotlin I'm trying to make a generic model in which some fields are fixed and only one field changes, so the model is class APIResponse( var msg: String? = null, var code: String? = null, var data: Any? = null // dynamic field ) I want to set data variable of this APIResponse class to other different types on the go with the help of a function: fun generateApiResponseAdapter(type: Any): APIResponse { return APIResponse(null, null, type) } so for example if I have a model as: class...