This code will cause some problems. In particular, it will generate two constructors with one Object parameter. The first constructor generates a bytecode equivalent to:
A() // a,b both default A(Object) // a set, b default A(Object, Object) // pass in both
The second generates this:
A(Object)
You can work around this problem by adding several types. Although groovy has dynamic typing, type declarations in methods and constructors still matter. For instance:
A(int a = 1, String b = "str") { ... } A(Map args) { ... }
As for good practices, I would just use one of groovy.transform.Canonical or groovy.transform.TupleConstructor . They will automatically create the correct property maps and positional parameter constructors. TupleConstructor provides only constructors, Canonical applies some other recommendations regarding equals , hashCode and toString .
source share