Nulls
Tim Peierls
tim at peierls.net
Mon Sep 24 05:03:47 PDT 2012
Mon, Sep 24, 2012 at 7:37 AM, Doug Lea <dl at cs.oswego.edu> wrote:
>
>> List<Class<?>> list = ...
>> Maps<Class<?>, ClassLoader> classLoadedMap =
>> list.mapped(Class::**getClassLoader).into(new HashMap<>());
>>
>> so Optional should be able to store null.
>>
>
No, Optional shouldn't store null to be able to support this usage. Use a
for loop or write an adapter for getClassLoader, but let's not distort
things just to support mapping to null. (Allow, yes; encourage, no.)
> This is how all these discussions seem to go: Some existing
> or potential abuse of null leads to rules allowing further
> abuse.
Time to take a stronger stand! :-)
> rule 2 is in my opinion a good compromise if by default the method that
>> returns
>> an Optional is written using the method that takes a default value as last
>> parameter.
>>
>
> If present Optionals can be null, the world is probably better off
> without them; so methods like findAny ONLY take the valueIfNone form.
But present Optionals should not null; there's no need for the valueIfNone
form; and poisonous things like getClassLoader should be dealt with closer
to the source, and not be allowed to pollute things downstream.
--tim
More information about the lambda-libs-spec-observers
mailing list