Option in Java 8

Mario Fusco mario.fusco at gmail.com
Thu Oct 11 07:27:15 PDT 2012


Hi all,

a couple of days ago I posted an article about how we could possibly
implement and use an Option monad in Java 8:

http://java.dzone.com/articles/no-more-excuses-use-null

Now, a friend of mine just found that you are already implementing
something very similar:

http://hg.openjdk.java.net/lambda/lambda/jdk/file/700bcae6d1da/src/share/classes/java/util/Optional.java

I'd be very happy to have an Option (and possibly a Validation) monad in
Java 8. However, I don't know if that is the last implementation available,
but if so I have to admit that I am a bit disappointed about it. The first
improvements that comes to me in mind are:

1. it should be an abstract class with 2 concrete implementations
2. a flatMap method would be very useful
3. it could implement the Iterable interface

What do you think about that?

Mario


More information about the lambda-dev mailing list