Optional fromNullable() (original) (raw)
Seibt, Volker volker.seibt at buenting.de
Fri Apr 26 00:30:03 PDT 2013
- Previous message: hg: lambda/lambda/jdk: 8006884: (fs) Add Files.list, lines and find
- Next message: Optional fromNullable()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In contrast to the Guava API Optional class in Java contains no static method "fromNullable()" which allows null-values and analogous should deliver Optional.empty() in this case.
It seems to be very comfortable in later "Optionalizing" return values like e.g.
Optional o = Optional.fromNullable(map.get(key));
instead of
Optional o = map.get(key) == null ? Optional.empty() : Optional.of(map(key));
or worse readable
T t = map.get(key); Optional o = t == null ? Optional.empty() : Optional.of(t);
to avoid calling map(..) twice.
Is there a reason why it's omitted?
- Previous message: hg: lambda/lambda/jdk: 8006884: (fs) Add Files.list, lines and find
- Next message: Optional fromNullable()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]