Optional used as method argument?
Roger Riggs
Roger.Riggs at Oracle.com
Fri Oct 2 12:49:36 UTC 2015
+1
The "no such value" makes me curious about the context.
The @param tag really should be saying something about the parameter.
The absence of an @throws (or class/package wide spec) documenting the
NPE for nulls
would indicate that null is allowed.
Roger
On 10/2/2015 4:10 AM, Remi Forax wrote:
> Hi Max,
> yes, It's usually not a good idea,
> creating an Optional is like a boxing, you create an object (and prey that escape analysis will work),
> usually null means there is no value so either you have two methods consume, something like consumeAValue(String) and consumeNoValue() or you have one method consumeAValue and you don't call it if there is no value.
>
> regards,
> Rémi
>
> ----- Mail original -----
>> De: "Wang Weijun" <weijun.wang at oracle.com>
>> À: core-libs-dev at openjdk.java.net
>> Envoyé: Vendredi 2 Octobre 2015 03:25:43
>> Objet: Optional used as method argument?
>>
>> I hear people saying Optional is usually used as return values. Can I use it
>> as an argument, like this?
>>
>> void consume(Optional<String> value)
>>
>> This way, I don't need to add spec like "@param value can be null if there is
>> no such value".
>>
>> Thanks
>> Max
>>
>>
More information about the core-libs-dev
mailing list