- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
At least he didn't do:
@Builder.default private List<String> names = null;
Admin
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.
Admin
Let me guess...the person who wrote that could say, "Ten days ago, I couldn't spell Pogrammer, now I are one!"
Admin
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.
Admin
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.
Admin
@search user -- "Non" "Not"... Schlemiel! Schlimazel! Hasenpfeffer Incorporated! -- We're gonna do it our way, yes our way....
Admin
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.
Admin
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.
Admin
@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
Admin
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.
Admin
Addendum 2022-05-02 09:57: Layout got mangled badly again. Can't fix, so read with caution.
Admin
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.
Admin
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."
Admin
The flip side of these time-saving shortcuts is the learning curve required to use them.
Admin
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.
Admin
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.)
Admin
Using Lombok is the real wtf.