Default parameters, function type examples fixed, tuples with named entries

This commit is contained in:
Andrey Breslav
2010-11-25 17:04:00 +03:00
parent dd49fc6ce2
commit 96040138f5
+14
View File
@@ -0,0 +1,14 @@
class Pair(x : Int, y : Int) {
class object {
fun copy(from : Pair, x : int = from.x, y : Int = from.y) = new Pair(x, y)
}
}
// One can say:
val p = new 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