It would be helpful to allow the following:
@NonNull
@Value
class NoNullValues {
String foo;
Collection<? extends String> bar;
}
which would be equivalent to
@Value
class NoNullValues {
@NonNull
String foo;
@NonNull
Collection<? extends String> bar;
}
Many of my data structures are immutable with no optional fields, so writing @NonNull on every field is repetitive.
You would probably also want to add a @Nullable, similar to @NonFinal, to simplify classes with almost no null fields allowed.
As a bonus, applying it to a method would apply it to all of the arguments.
Let's quote from the current @NonNull documentation:
A
@NonNullon a parameter of an abstract method used to generate a warning; starting with version 1.16.8, this is no longer the case, to acknowledge the notion that@NonNullalso has a documentary role. For the same reason, you can annotate a method as@NonNull; this is allowed, generates no warning, and does not generate any code.
This means that your last suggest would probably break compatibility.
About the rest, I think that it is ok, although annotating a class with @NonNull seems to be odd for me since it is not just denoting anymore that a value can't be null and is instead denoting that it can't have null as an internal data. Maybe calling it @ForbidNullValues, which would also apply to the parameters?
@victorwss Yes.
There's @ParametersAreNonnullByDefault in jsr305 used for validators and Lombok could have its own annotation forcing the runtime checks.
I've proposed a rather general @ForbidNull years ago, but nobody seemed to care.
@Maaartinus Definitely agreed. Unfortunately, for reasons that I don't know, lombok's devs are sometimes too quiet about issues and proposals.
I suspect it's simply a time management issue. Many people asking for
stuff, not so many people actually working on code.
Frankly, the best and quite possibly only way to fix this is to simply
pick up stuff yourself.
Working code for a new feature is going to have about a zillion times
better chance to result in a new feature than mere discussion on a board.
On Mon, Mar 26, 2018 at 1:32 AM, Victor Williams Stafusa da Silva <
[email protected]> wrote:
@Maaartinus https://github.com/Maaartinus Definitely agreed.
Unfortunately, for reasons that I don't know, lombok's devs are sometimes
too quiet about issues and proposals.—
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/1619#issuecomment-376012775,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAKCRcIMzmurC3jj88ZB_YfrXbWnobvaks5tiCkRgaJpZM4SylcN
.
--
"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
Totally agree with the suggestion. At the very least, @NonNull should not even be allowed on the class level, if it has no effect anyways.
Most helpful comment
@victorwss Yes.
There's
@ParametersAreNonnullByDefaultin jsr305 used for validators and Lombok could have its own annotation forcing the runtime checks.I've proposed a rather general
@ForbidNullyears ago, but nobody seemed to care.