question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional.or(Supplier<? extends Optional<T>> supplier)

See original GitHub issue

Would be useful for usecases like:

someOptional = firstSuplier().or(secondSupplier).or(thirdSupplier)

Right now it should be written as

if (!someOptional.isPresent()) {
  someOptional = secondSupplier();
}

if (!someOptional.isPresent()) {
  someOptional = thirdSupplier();
}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kilotarascommented, Mar 4, 2018

Added in Java 9. Could still be useful to people on Java 8

0reactions
cpovirkcommented, Jun 13, 2018

Kevin recently said:

I’m sorry, but the legacy Optional class is indeed frozen.

I’ll close this and any other Optional feature requests I see floating around.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there java.util.Optional.or(Supplier ... - Stack Overflow
I wanted to find a short implementation for the behavior: return another java.util.Optional if the current one is empty. JDK 9 has the...
Read more >
Optional (Java SE 10 & JDK 10 ) - Oracle Help Center
Returns an Optional describing the given value, if non- null , otherwise returns an empty Optional . Optional<T>, or​(Supplier<? extends Optional<? extends T>> ......
Read more >
Java Optional - orElse() vs orElseGet() - Baeldung
Clearly, orElse() takes any parameter of a type T, whereas orElseGet() accepts a functional interface of type Supplier that returns an ...
Read more >
Optional or() method in Java with examples - GeeksforGeeks
public Optional<T> or(Supplier<T> supplier). Parameters: This method accepts supplier as a parameter of type T to generate an Optional ...
Read more >
Optional (Guava: Google Core Libraries for Java 19.0 API)
A non-null Optional<T> reference can be used as a replacement for a nullable T reference. ... @Beta public abstract T or(Supplier<? extends T>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found