https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
d

Duane Malcolm

03/01/2023, 7:19 PM
Is there a way to have different input types for setters? For example,
Copy code
var bar: String = "5"
var foo: String
    get() { return bar }
    set(value: String) { bar = value }
    set(value: Int) { bar = value.toString() }
    set(value: Float) { bar = round(value).toInt().toString() }
a

Adam S

03/01/2023, 7:26 PM
there's a compiler plugin for this, but I think it's not been officially announced https://github.com/JetBrains/kotlin/tree/master/plugins/assign-plugin It'll be used in an upcoming Gradle release Try taking a look at this PR https://github.com/gradle/gradle/pull/22240
d

Duane Malcolm

03/01/2023, 7:36 PM
Thanks @Adam S, I might wait for the release unless I get impatient.
e

ephemient

03/01/2023, 8:18 PM
the assignment plugin is about
Copy code
val foo: Property<String>
foo = ...
d

Duane Malcolm

03/02/2023, 5:58 AM
Thanks @ephemient, I like the looks of the setter overloading. It's exactly what I'm looking for but it looks like I'll have to wait. I'm using
setValue
functions at the moment and that will do until this feature eventuates.
5 Views