mg6maciej
04/22/2017, 2:07 PMcopy
for certain data classes?
I have a class where first two props are `Int`s and wanted to change the second, but forgot to use name of property. Found after like 5 minutes.snrostov
04/22/2017, 2:17 PMclass Barrier internal constructor()
val barrier_ = Barrier()
data class Ugly(val i: Int, val j: Int) {
fun safeCopy(barrier: Barrier = barrier_, i: Int = this.i, j: Int = this.j)
= this.copy(i = i, j = j)
}
fun main(args: Array<String>) {
Ugly(1, 2).safeCopy(1, 2) // compile time error
Ugly(1, 2).safeCopy(i = 1, j = 2)
}
mg6maciej
04/22/2017, 2:24 PMRuckus
04/22/2017, 4:14 PMNothing
hack (vararg barrier: Nothing
as the first parameter)