Loose ends: Optional
Remi Forax
forax at univ-mlv.fr
Sun Jun 2 12:15:26 PDT 2013
On 06/02/2013 06:56 PM, Brian Goetz wrote:
>>> I still struggle with the fact that with the current API I still have to make my own object to Optional converter to handle nulls in what I think is a sane way.
>> yes, Optional have not the same semantics as Optional (from Guava).
> Can you clarify this? Is this anything more than the lack of an Optional.ofNullable(T) factory?
Yes.
But if you add that, you will have code like this:
List<Optional<Badge>> bagdes = people.streams().map(p ->
Optional.ofNullable(map.get(p.getName())).collect(toList());
That's why I was against Optional since the beginning, because if you
introduce it,
the whole community will have to deal with beast like the one above.
Trading a null to an Optional doesn't solve the issue, filtering the
null out the of stream is the solution:
List<Badge> badges = people.streams().map(p ->
map.get(p.getName()).filter(Objects::isNotNull).collect(toList());
Rémi
More information about the lambda-libs-spec-experts
mailing list