Loose ends: Optional
forax at univ-mlv.fr
Mon Jun 3 03:05:04 PDT 2013
On 06/03/2013 08:11 AM, Joe Bowbeer wrote:
> I'd like to see a compare-and-contrast between what is proposed for
> Java8 and Guava's Optional and Scala's Option.
> Is the criticism that Brian is fielding now a replay of prior
> criticism of Guava's Optional?
> How have Guava's user been dealing with its intentionally more limited
There are also some comments in the comment section of this wiki page:
The number one criticism seems to be the lack of a method bind like in
but because Java is not Haskell, the exact operation needed is neither a
map nor a flatMap,
it's a composition of flatMap and Optional.ofNullable().
So the issue is more how to deal with the return value of a method that
can be null but that doesn't return an Optional.
I still think and this is the conclusion of one of the blog cited above
that the elvis syntax (?.)
is the best way to deal with this issue.
I don't see how to solve this issue without introducing
> Have the new methods added in more recent versions helped?
> Optional<V> transform(Function<T,V>)
> Iterable<T> presentInstances(Iterable<Optional<T>)
> Set<T> asSet()
asSet() is interesting because the users ask to see Optional as a
presentInstances is an admission of weakness, people have already
created an Iterable of Optional
and the iterable needs to be filtered in a post processing phase.
> On Sun, Jun 2, 2013 at 6:11 PM, Sam Pullara <spullara at gmail.com
> <mailto:spullara at gmail.com>> wrote:
> My opinion remains the same, we should have these methods and probably
> a few more.
> On Jun 2, 2013, at 6:02 PM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
> >> Is Optional crippled if we consider that it's just an object
> that represent a value or no value ?
> >> I don't think so.
> > Of the people that have an opinion on this subject, you would be
> in a very, very, very, very, very small minority. I have received
> over a hundred e-mails and tweets on the subject where people are
> essentially saying "optional is crippled without these" -- and
> none expressing the opposite opinion. I realize this is vastly
> unscientific, and it represents a vanishingly small and
> self-selected portion of the Java developer base, but of the
> people who care, it is basically lots of people saying "we need
> this" vs a few saying "but if I give it to you, others will misuse
> >>> It is something we want to avoid -- I will certainly avoid it
> in my code, and criticize any code I see using this (or any of ten
> million other bad programming techniques.) The world is full of
> useful tools that that interact dangerously, such as bleach and
> ammonia or toasters and bathtubs.
> >> Wrong example, I don't know in US but in France you can not
> have a power outlet too close to a bathlub :)
> >> That's exactly what we are talking about.
> > And extension cords are illegal in France too? :)
> >> But you can don't add these 3 methods because they send the
> wrong message.
> > I get what you're saying about what message it sends, and that's
> a reasonable thing to worry about. On the other hand, making
> toasters illegal because we already have bathtubs and extension
> cords is also worrisome.
> > I would like to hear from other members of the EG on this.
More information about the lambda-libs-spec-observers