Problem
I would very much like to have fluent getters (fluent in the sense "no prefix") but simultaneously have classic (prefixed) setters and withers.
AFAIK there's no way to do it using the @Accessors annotation in its current form.
Example
What I'd like to get:
car.color()
car.setColor(Color.BLUE)
car.withColor(Color.BLUE)
What I get with
@Accessors(fluent=true)
car.color()
car.color(Color.BLUE)
Rationale
As you can see, the main problem is that setters become indistinguishable from withers. I consider this a very serious problem so I never use @Accessors when I need a wither.
But another problem is that such setter/wither doesn't tell me what it does:
So the "set" prefix (saying "I change the field's value") and the "with" prefix (saying "I clone the object, I set the field's value in the clone, and return the clone") are crucial to me.
Ideas
I have the following ideas about how to solve this issue in a backward-compatible manner:
enum AccessorTarget { GETTER, SETTER, WITHER }
and that (by default) would be set to all of them. Of course, it should also come with lombok.accessors.targets config option (which would support += and -=, like lombok.accessors.prefix).As you can see, the main problem is that setters become indistinguishable from withers. I consider this a very serious problem so I never use @Accessors when I need a wither.
I tried to reproduce the behavior with lombok.accessors fluent and chain flags set to true.
Please, let me know how you achieved it that your withers have a prefix in presence of fluent=true.
- I don't need to "hear" what a getter does because I don't consider car.color() as "getting" the color - I consider it as merely accessing it so it "reads" fine.
- But car.color(Color.BLUE) is always non-intuitive to me, no matter whether it's a setter or a wither. It's because it's not immediately obvious whether it returns a Color or does something else.