I often have a class with properties that are initialized at instantiation, like
class C { var x = 10 var y = v * 2 // v is some variable } val c = C() then properties of c are changed, and later I need to re-initialize the properties (so that c.x is 10 again and c.y is v*2, where the value of v may have changed).
My current approach is to initialize the properties with dummy values (or alternatively use lateinit and type annotations), and assign the desired values in an extra function ini like
class C { var x = 0 var y = 0 init { ini() } fun ini() { x = 10 y = v * 2 } } then I call c.ini() to re-initialize.
Is there a better (more succinct) way that avoids the dummy values?
Note that in JavaScript I can simply write
class C { constructor() { this.ini() } ini() { this.x = 10 this.y = v * 2 } }
C?