Default parameters, function type examples fixed, tuples with named entries
This commit is contained in:
@@ -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
|
||||||
Reference in New Issue
Block a user