I cannot find how to pass the reference of the objects so that I can let them point to a new location in the memory. How to do this in Kotlin?
Code:
class Parent { } class Child : Parent { } class GlobalDataHolder { var globalChildVriable: Child? = null // imagine this is a static variable and can be accessed anywhere } class Activity() { var variable1 = Child() Helper.init(variable1, GlobalDataHolder.globalChildVriable) // inside onCreate() } class Helper { initStuff(variable1: Parent, globalVariable: Parent?) { if (globalVariable == null) { globalVariable = variable1 // error saying val cannot be re-assigned } else { variable1 = globalVariable!! } } } I want variable1 and globalVariable to be modifiable. So the original owners of them will have the latest values.