Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting an optional value should not require wrapping in "Optional" #184

Closed
koppor opened this issue Jul 1, 2024 · 2 comments
Closed

Setting an optional value should not require wrapping in "Optional" #184

koppor opened this issue Jul 1, 2024 · 2 comments

Comments

@koppor
Copy link

koppor commented Jul 1, 2024

At 62011fe#diff-9894c8ca988dd9ba18c16d1cc0176ca25e915f1b212f12e9c5f285d44fa10e72R81, the value of the example optional Property "b" was made using .b(Optional.of("bbbb"). I wonder, why one could not simply write .b("bbbb")? The method b can create the Optional by itself. - IMHO the code would be more readable.

@Randgalt
Copy link
Owner

Randgalt commented Jul 1, 2024

You can get that behavior by using addConcreteSettersForOptional = true. E.g.,

@RecordBuilder
@RecordBuilder.Options(builderMode = RecordBuilder.BuilderMode.STAGED_REQUIRED_ONLY, interpretNotNulls = true, useImmutableCollections = true, addConcreteSettersForOptional = true)
public record OptionalListStaged(int a, Optional<String> b, double c, List<Instant> d, @Null String e, String f) {
}

@Randgalt Randgalt closed this as completed Jul 1, 2024
@koppor
Copy link
Author

koppor commented Jul 1, 2024

Thank you for the quick reply! 🤩 (I was about to comment after reading through https://github.com/Randgalt/record-builder/blob/master/options.md)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants