Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 12
    Google's guava has an optional implimention for Java 6+. Commented May 27, 2013 at 17:30
  • 20
    It's very important to emphasise that using Optional only with ifPresent() does not add much value above normal null checking. It's core value is that it is a monad that can be used in function chains of map/flapMap, which achieves results similar to the Elvis operator in Groovy mentioned elsewhere. Even without this usage, though, I find the orElse/orElseThrow syntax also very useful. Commented Oct 9, 2014 at 14:57
  • This blog has a good entry on Optional winterbe.com/posts/2015/03/15/avoid-null-checks-in-java Commented Dec 9, 2015 at 0:05
  • 8
    Why people have tendency to do this if(optional.isPresent()){ optional.get(); } instead of optional.ifPresent(o -> { ...}) Commented Mar 7, 2018 at 15:06
  • 1
    So, other than the API contractual hints, it's really just about catering to functional programmers who enjoy chaining methods endlessly. Commented Aug 9, 2018 at 17:39