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

set java.util.Optional constructor fields default to Optional.empty(). #1

Open
Zegveld opened this issue Aug 4, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@Zegveld
Copy link
Contributor

Zegveld commented Aug 4, 2023

If I have an Optional field it would be nice that the instantiation would automatically be empty.
That way I can never have a null-value here.

Example:

@Builder
class MyClass {
  Optional<String> someField;
  // setter/getter/constructor
}

should result in:

class MyClassBuilder {
    Optional<String> someField = Optional.empty();
    // setters and build method.
}
@Nutstree
Copy link
Contributor

Nutstree commented Aug 5, 2023

Is this only for Optionals? It could be on purpose null for other objects. Actually the writer could have some design freedom to initialize the object personally.

@Zegveld Zegveld added the enhancement New feature or request label Sep 26, 2023
@Zegveld
Copy link
Contributor Author

Zegveld commented Sep 26, 2023

If you want to do default initialization you can simply do that in a constructor and not have the builder handle that. The idea for this is that unset java.util.Optional fields which are required for a constructor are default set to Optional.empty().

@Zegveld Zegveld changed the title set java.util.Optional fields default to Optional.empty(). set java.util.Optional constructor fields default to Optional.empty(). Nov 7, 2023
@Zegveld
Copy link
Contributor Author

Zegveld commented Dec 11, 2023

related to #39

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

No branches or pull requests

2 participants