| class Pair(x : Int, y : Int) { | |
| companion object { | |
| fun copy(from : Pair, x : Int = from.x, y : Int = from.y) = Pair(x, y) | |
| } | |
| } | |
| // One can say: | |
| val p = Point(1, 2) | |
| val p1 = Point.Copy(p, x = 2) | |
| val p2 = Point.Copy(p1, y = -1) | |
| val p3 = Point.Copy(p) | |
| // Such copy(...) methods can be automatically generated by the compiler | |
| // whenever there is a primary constructor |