18 lines
501 B
Text
18 lines
501 B
Text
module NamedParams {
|
|
const Point(Int x, Int y) {
|
|
Point with(Int? x=Null, Int? y=Null) {
|
|
return new Point(x ?: this.x, y ?: this.y);
|
|
}
|
|
}
|
|
|
|
@Inject Console console;
|
|
|
|
void run() {
|
|
Point origin = new Point(0, 0);
|
|
console.print($"origin={origin}");
|
|
Point moveRight = origin.with(x=5);
|
|
console.print($"moveRight(x=5)={moveRight}");
|
|
Point moveUp = moveRight.with(y=3);
|
|
console.print($"moveUp(y=3)={moveUp}");
|
|
}
|
|
}
|