One of the String member variables of my class is Optional. Does it makes sense to mark it with Lombok annotation @NonNull ?
I would like to ask the same question in case that member variable is Map instead of String. Will the answer change ?
Optional main point is to make fluent API. Field is not and should not be a part of API.
What is the difference for you between Optional<Object> obj and Object obj in fields?
Both of fields could be annotated with @NotNull.
Annotating a field with @NotNull will give you the same result as annotating an Optional but without any extra calls like ifPresent(). If you want to use Optional to apply chaining operations to a field - you are using Optional in a wrong way. There in no reason to use Optional in field.
You can read more in openjdk mailing list optional discussion.
Having Optional enables to do fluent API mail.openjdk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With