8000 Optional.ofNullable is generally more usable in conjucture with .orElse() by zoomix · Pull Request #19 · winterbe/java8-tutorial · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@zoomix
Copy link
@zoomix zoomix commented Dec 17, 2015

It allows for a cleaner look when initializing variables.

I.e, instead of

if(someting == null) {
    something = new Something();
}

you can go

something = Optional.ofNullable(something).orElse(new Something);

Using

Optional.of(null).orElse("something");

throws a NullPointer

@winterbe winterbe closed this Jun 29, 2019
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

Successfully merging this pull request may close these issues.

2 participants

0