What different between this type of constructor?
class ColorsArray(context: Context) {}
and
class ColorsArray(var context: Context){}
The second class not only declares a constructor that takes a Context, but it also has a property named context where it saves the value passed into the constructor. You can then access this like so:
val colorsArray = ColorsArray(context)
println(colorsArray.context)
Since you've declared it as a var and not a val, this can also be reassigned.
colorsArray.context = someOtherContext
Properties declared in the primary constructor are covered in the docs here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With