Optional used as method argument? (original) (raw)
Remi Forax forax at univ-mlv.fr
Fri Oct 2 08:10:23 UTC 2015
- Previous message: Optional used as method argument?
- Next message: Optional used as method argument?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 value) This way, I don't need to add spec like "@param value can be null if there is no such value". Thanks Max
- Previous message: Optional used as method argument?
- Next message: Optional used as method argument?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]