https://kotlinlang.org logo
Title
c

crummy

05/10/2019, 5:08 AM
Can I override a setter for a constructor
var
?
o

Ovsyannikov Alexey

05/10/2019, 7:23 AM
No
t

Tom Prior

05/10/2019, 12:31 PM
@crummy you can make it a constructor parameter instead of a property and then create the property separately with a custom initialisation. class MyClass(name: String) { var name: String = name + “add something to name” }
👍 1
m

marco

05/10/2019, 3:02 PM
@Tom Prior why you don't use the init block ?
👍 1
t

Tom Prior

05/13/2019, 7:23 PM
@marco yep I would definitely use an init block if it were more complex then a one liner initialization but, for the purpose of answering @crummy question, I was just showing how to initialize a mutable property as I think that’s what he was asking..but yeah absolutely, an init block is where I would usually put primary constructor initialization code if it is more complex then a one liner to initialize a property.
👍 1