I suspect there are many reasons not to do this, b...
# language-proposals
k
I suspect there are many reasons not to do this, but I'm sort of just thinking aloud here; why not have the ability to define multiple setters on a property? For example, if I wanted to set a timestamp field either via a
Long
or a
Date
, I'd do:
Copy code
var timestamp: Long = 0

fun setTimestamp(date: java.util.Date) {
    timestamp = date.getTime()
}

fun main(args: Array<String>) {
    val date = java.util.Date()
    setTimestamp(date)
    println(timestamp)
}
It might be nice to instead do:
Copy code
var timestamp: Long = 0
	set(value: Long) { // Maybe this could be omitted entirely since it's just the default setter behavior
        field = value
    }
	set(value: java.util.Date) {
        field = value.getTime()
    }

fun main(args: Array<String>) {
    val date = java.util.Date()
    timestamp = date
    println(timestamp)
}
I suppose it might be argued that you shouldn't be in any situations where you find it advantageous to be able to set a property directly like this from any amount of arbitrary types, though?