Closed GoogleCodeExporter closed 9 years ago
I don't think the semantics of Supplier would be questionable at all here. What
you want is something that has the ability to supply a value to return if
necessary. Function doesn't make sense given that there's nothing that the
Optional itself can provide as the input. For example, all of your examples
would be well served by a supplier that does message formatting:
return optUser.or(new MessageFormattingSupplier("[unknown user #{0}] (last checked at {1})", userId, new Date()));
It would even be possible to create a Supplier<T> that takes a Function<F, T>
and an input F if you really wanted.
All that said, I imagine this falls in with filter/transform methods for
Optionals which have been avoided so far, probably because of the difficulties
associated with functional stuff in Java. If it were just a matter of putting
{} around the argument expression it would be an obvious win.
Original comment by cgdec...@gmail.com
on 27 Jul 2011 at 12:15
It does seem logically consistent with the two or overloads we already have.
Original comment by fry@google.com
on 28 Jul 2011 at 5:38
Original comment by kurt.kluever
on 29 Jul 2011 at 9:15
Original comment by cpov...@google.com
on 1 Sep 2011 at 9:22
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
j...@nwsnet.de
on 27 Jul 2011 at 11:19