0

I observed the following strange phenomenon. That lombok picks setXyz() as setter's name in only three out of the four cases; and in the fourth case, it picks setIsXyz()

package use_lombok;

import lombok.Data;

@Data
public class MyClass {
    boolean foo;
    Boolean bar;
    boolean isBlack;
    Boolean isRed;
    public static void main(String[] argv) {
        MyClass o1 = new MyClass();
        o1.setFoo(true);
        o1.setBar(true);
        o1.setIsRed(true);   // This is inconsistent with the others
        o1.setBlack(true);
        System.out.println(o1.toString());
    }
}

Not a duplicate of a previous question

I am aware of the discussion in another StackOverflow Q&A (Lombok annotation @Getter for boolean field), but I am still not happy with the conclusion (that it is the way Lombok is designed). I think Lombok should treat boolean and Boolean uniformly.

leeyuiwah
  • 6,562
  • 8
  • 41
  • 71
  • "I think Lombok should treat boolean and Boolean uniformly" Well, sorry, it doesn't. – Michael Feb 04 '19 at 15:55
  • @Michael -- Can you provide the link of the other answer? I cited one but I don't think mine is a duplicate of the other (https://stackoverflow.com/questions/42619986/lombok-annotation-getter-for-boolean-field) – leeyuiwah Feb 04 '19 at 15:56
  • "Any variation on boolean will not result in using the `is` prefix instead of the `get` prefix; for example, **returning java.lang.Boolean results in a `get` prefix, not an `is` prefix.**" – Michael Feb 04 '19 at 15:58
  • I know that statement in the small print. The question is -- is this design justified? Does it help programmers? – leeyuiwah Feb 04 '19 at 16:10
  • That question is opinion-based which makes it off-topic for Stack Overflow. Whether it's good or bad, that's the behaviour that they've defined. Don't like it? You can fork the project; it's [open source](https://github.com/rzwitserloot/lombok). – Michael Feb 04 '19 at 16:14
  • Well, I would accept answer/information that illustrates how that design helps programmer, or, alternatively, how it is necessary due to some other considerations. – leeyuiwah Feb 04 '19 at 16:15
  • Just saying "that is the way it is" is more opinionated than "we have to use this design because of reasons X and Y", or "because in situation W, the design actually creates less confusion" or something like that. – leeyuiwah Feb 04 '19 at 16:17
  • Unless the lombok developers show up, all you'll get is conjecture. – Michael Feb 04 '19 at 16:20
  • Oh ... I thought you were one of the designers ... sorry :-) – leeyuiwah Feb 04 '19 at 16:21
  • The reason is Java's bean spec. It states that only `boolean`s get an `is` prefix, nothing else, not even `Boolean`s. So Lombok is designed to also treat only `boolean` special, nothing else. – Jan Rieke Feb 04 '19 at 20:54

0 Answers0