• linepro (unregistered)

    At least he didn't do:

    @Builder.default private List<String> names = null;

  • search user (unregistered)

    The fine point here is that Lombok actually does automagically insert null checks for fields annotated in the right way, where "in the right way", according to the documentation, is "various annotations generally named @NonNull", including Lombok's own one. The only problem is that the @NotNull annotation has a slightly different name, so it does not count.

  • J. Random PMP (unregistered)

    Let me guess...the person who wrote that could say, "Ten days ago, I couldn't spell Pogrammer, now I are one!"

  • (nodebb)

    Write a one line annotation to generate a one line no argument constructor, instead of writing a one line no argument constructor.

    While opening a brewery isn't my thing, I may start visiting more breweries, that's for sure.

  • PMF1 (unregistered) in reply to J. Random PMP

    Just my guess as well. There are just to many wannabe-programmers out there so that projects consisting of copy-pasted tutorial/stackoverflow code are unavoidable.

    The problem for the companies is that hiring the expensive "experts" doesn't make anything better, as demonstrated to often on this site as well.

  • (nodebb)

    @search user -- "Non" "Not"... Schlemiel! Schlimazel! Hasenpfeffer Incorporated! -- We're gonna do it our way, yes our way....

  • (nodebb) in reply to Mr. TA

    While opening a brewery isn't my thing, I may start visiting more breweries, that's for sure.

    Not a beer fan myself, but there's a proper distillery nearish to where I live (with guided tours(1) and everything), and sometimes I feel an urge to go and visit there again, if for no other reason than to sample the wares...

    (1) Where I learned that in fact, the vapour distilling process extracts more alcohol than water from the mix, so they have to separate the alcohol from the water/alcohol vapour, and put it back in the whiskey... Um. Having also separated the ethanol from the methanol.

  • (nodebb) in reply to Steve_The_Cynic

    Separating the methanol and ethanol can be a headache for the distiller due to their similar boiling points, but if it is not done properly the consumers will be getting a headache and hopefully nothing worse.

  • Heinebold (unregistered)

    @AllArgsConstructor is necessary because @NoArgsConstructor is in place. @Data only generates constructors if no other constructors are created or manually implemented.

    WIth a correct @NonNull instead of @NotNull, the generated @Builder would very well take care of the List not being null, the empty constructor would then be the only way to make that List null.

    And the accessors being not private is a normal thing to do, you have a private field with public accessors.

    That said, I also wonder why the f a class this small would need all that stuff (or why it even exists instead of directly using the list). The explicit NoArgsConstructor suggests though that the excessive boilerplate (generated or not) is there to satisfy some other framework, because that's usually the main or only reason for a default constructor on a class that normally should be properly initialized

  • Heinebold (unregistered) in reply to Mr. TA

    Write a one line annotation to generate a one line no argument constructor, instead of writing a one line no argument constructor.

    If you are using other generator annotations (on a class where the end result makes more sense...), I find it clearer this way than having it mixed.

  • (nodebb) in reply to Nutster

    Separating the methanol and ethanol can be a headache for the distiller due to their similar boiling points, but if it is not done properly the consumers will be getting a headache and hopefully nothing worse. Can't they turn a blind eye?

    Addendum 2022-05-02 09:57: Layout got mangled badly again. Can't fix, so read with caution.

  • MaxiTB (unregistered)

    Java really loves their boilerplate annotations which should make up for the lack of any language features. And yeah, that's how you write it in C# (with non-nullable reference types enabled, which is now the default anyway):

    public class NameHolder { public List<string> Names { get; } = new(); } // Done.

  • Ryan (unregistered)

    I can't imagine the number of annotations this would have grown to if the specs included: "None of the strings in the list can be null."

  • Yikes (unregistered)

    The flip side of these time-saving shortcuts is the learning curve required to use them.

  • ronin (unregistered)

    The only WTF I see here is using the wrong "non-null" annotation.

    If you annotate a private member, Lombok will automatically copy the annotation to getters, setters and constructor parameters in the generated code. The usefulness of the annotation depends on which one you use:

    lombok.NonNull, javax.annotation.Nonnull and org.springframework.language.NonNull won't create any nullchecks in the generated code, nor prevent you from setting the member to a null value at runtime, but they will cause the IDE to give you a warning when you try to pass a value that hasn't been null-checked before. On the other hand, when none of these annotations are set, the IDE will give you a warning about potential NullPointerExceptions if you write something like nameHolder.getNames().iterator(). That's the whole point of these annotations; none of them will do anything at runtime.

    The annotation javax.validation.constraints.NotNull (which apparently was used her) WILL do something at runtime, but only if used in context with a validation framework.

  • Mike Rosoft (unregistered) in reply to nerd4sale

    There was a case in the Czech Republic: a guy has found out that ethanol is being used as an antidote for methanol poisoning. So he arranged with another guy to test it in practice (and to make money from it): They mixed a huge tank of 50% ethanol and 50% methanol, and sold the mixture on the black market so that alcoholic drinks could be made from it. (About 50 people died as a result, and the two were sentenced to life in jail.)

  • LordOfThePigs (unregistered) in reply to ronin
    Comment held for moderation.
  • SyntaxError (unregistered)

    Using Lombok is the real wtf.

  • wasim (unregistered)
    Comment held for moderation.

Leave a comment on “Annotated Private Members”

Log In or post as a guest

Replying to comment #:

« Return to Article