@AllArgsConstructor seemingly generates the order of constructor arguments based on the position of fields within the actual source file. If one has two fields with the same type, the seemingly innocuous change of switching the declaration order will produce compile-able, but buggy code as the constructor arg order is now changed.
Generate arg order using something more predictable, such as alphabetical ordering; or better yet, deprecate @AllArgsConstructor :)
This is a matter of perception and preference. Once you know the order of
the fields changes the order of the constructor arguments it's actually
quite useful to be able to reorder the arguments as you wish.
If you want to create your objects in a way that does not depend on the
order of the fields, use @Builder
On Wed, Apr 10, 2019 at 2:53 PM R. Matt McCann notifications@github.com
wrote:
The Problem
@AllArgsConstructor https://github.com/AllArgsConstructor seemingly
generates the order of constructor arguments based on the position of
fields within the actual source file. If one has two fields with the same
type, the seemingly innocuous change of switching the declaration order
will produce compile-able, but buggy code as the constructor arg order is
now changed.
The SolutionGenerate arg order using something more predictable, such as alphabetical
ordering; or better yet, deprecate @AllArgsConstructor
https://github.com/AllArgsConstructor :)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/rzwitserloot/lombok/issues/2094, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAKCRcymbAke8U_H-AN1mCLUaIDfiSI9ks5vfd7LgaJpZM4cm7Ox
.
--
"Don't only practice your art, but force your way into it's secrets, for it
and knowledge can raise men to the divine."
-- Ludwig von Beethoven
I think it's implemented this way on purpose. It is reasonable to let the parameter order follow the order of field declarations.
Using any other order has exactly the same drawback: For instance, if the annotation would use alphabetical ordering, renaming a field could similarly create a compatible constructor.
Deprecating is also clearly not an option, as so many developers rely on this feature. If you feel this annotation is too dangerous, then simply switch it off in your project by lombok.allArgsConstructor.flagUsage = error.
Most helpful comment
I think it's implemented this way on purpose. It is reasonable to let the parameter order follow the order of field declarations.
Using any other order has exactly the same drawback: For instance, if the annotation would use alphabetical ordering, renaming a field could similarly create a compatible constructor.
Deprecating is also clearly not an option, as so many developers rely on this feature. If you feel this annotation is too dangerous, then simply switch it off in your project by
lombok.allArgsConstructor.flagUsage = error.