Ruckus
02/23/2021, 6:21 PMget
and set
operators
Currently, you can have default parameters in get
and set
operators, but you cannot address them out of order. For example, given this:
class Thing<T>(...) {
operator fun set(coordinates: IntArray, depth: Int = this.depth, isDestructive: Boolean = true, value: T) { ... }
}
Which allows this:
thing[coordinates] = value
But it would be nice to be able to do this:
thing[coordinates, isDestructive = false] = value
However, there doesn't appear to be a way to do so. Instead, I'm stuck either adding a second set
operator, or doing
thing[coordinates, thing.depth, false] = value
(Which only works assuming thing.depth
is accessible. If not, and there isn't an overloaded set
operator, I don't believe it's possible.)
Yes, I am aware this can be simply worked around by calling the set function directly and not using the operator, which is why this is a proposal and not a bug report.Ruckus
02/23/2021, 6:29 PMoperator fun get(vararg coordinates: Int, depth: Int = this.depth)
Ky Leggiero
02/27/2021, 11:32 PM