by Anonymous » 22 Aug 2025, 09:53
Groovy unterstützt sowohl Standard als auch benannte Argumente. Ich sehe sie einfach nicht zusammenarbeiten.def a1 = new A(2)
def a2 = new A(a: 200, b: "non default")
class A extends SomeBase {
def props
A(a=1, b="str") {
_init(a, b)
}
A(args) {
// use the values in the args map:
_init(args.a, args.b)
props = args
}
private _init(a, b) {
}
}
< /code>
Ist es im Allgemeinen eine gute Praxis, beide gleichzeitig zu unterstützen? Ist der obige Code der einzige Weg dazu?
Groovy unterstützt sowohl Standard als auch benannte Argumente. Ich sehe sie einfach nicht zusammenarbeiten.def a1 = new A(2)
def a2 = new A(a: 200, b: "non default")
class A extends SomeBase {
def props
A(a=1, b="str") {
_init(a, b)
}
A(args) {
// use the values in the args map:
_init(args.a, args.b)
props = args
}
private _init(a, b) {
}
}
< /code>
Ist es im Allgemeinen eine gute Praxis, beide gleichzeitig zu unterstützen? Ist der obige Code der einzige Weg dazu?