Closed GoogleCodeExporter closed 9 years ago
How about using Optional?
Object result = Optional.fromNullable(expensiveOperationThatIsUsuallyNonnull())
.or(evenMoreExpensiveOperationThatRarelyNeedsToExecute())
Original comment by kurt.kluever
on 11 Aug 2011 at 3:01
Ah, that is even better. I'm not particularly familiar with optionals yet, but
I'm looking forward to that being released. I see that the `of` method takes a
supplier, so that would cover my use case. This issue can be closed. Thanks,
Kurt :)
Original comment by raymond....@gmail.com
on 11 Aug 2011 at 3:14
Rather, the `or` method.
Original comment by raymond....@gmail.com
on 11 Aug 2011 at 3:15
firstNonNull should mention Optional in its doc!
Original comment by kevin...@gmail.com
on 11 Aug 2011 at 3:26
Original comment by kurt.kluever
on 11 Aug 2011 at 4:42
> Object result = Optional
> .fromNullable(expensiveOperationThatIsUsuallyNonnull())
> .or(evenMoreExpensiveOperationThatRarelyNeedsToExecute())
This only makes sense if the method to calculate the alternative value is
executed lazily, which is why I requested `Optional.or(Supplier)` in the first
place.
Original comment by j...@nwsnet.de
on 16 Aug 2011 at 7:45
Well you'll be happy to hear that I added Optional.or(Supplier) a couple weeks
ago!
http://code.google.com/p/guava-libraries/source/detail?spec=svn643&r=593
Original comment by kurt.kluever
on 16 Aug 2011 at 1:20
I've seen it already (and raymond, obviously, too), but thanks nevertheless :)
Original comment by j...@nwsnet.de
on 16 Aug 2011 at 1:47
Original comment by kurt.kluever
on 16 Aug 2011 at 10:21
Original comment by cpov...@google.com
on 1 Sep 2011 at 9:20
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
raymond....@gmail.com
on 11 Aug 2011 at 2:27