Optional require(s) NonNull
zhong.j.yu at gmail.com
Wed Oct 31 09:21:39 PDT 2012
On Wed, Oct 31, 2012 at 10:53 AM, Olexandr Demura
<oleksander.demura at gmail.com> wrote:
> May be we do not need Optional at all?
> It does less than most of randomly chosen developers expect.
> It has very limited usage and restricted applicability.
> Could exception mechanism be used instead?
> Like Peter Levart proposed in "inference of throws type parameters in SAMs"
I like it a little more than Optional. Very often, when we call a
method like `findFirst()`, we know it will succeed, per application
logic. Forcing us to pretend that we don't know and we must test the
result for present-ness is an undue tax, and it reduces clarity of
code. In Levart's design, one can simply boldly invoke `findFirst()`
without any protection, if he knows it'll succeed.
I don't understand why null pointer is so dreaded. If it's up to me,
`getFirst()` returns null if not found, and we can have some static
elvis( getFirst(), defaultValue )
even better if Java has "static extension methods"
where exp#foo(args) means foo(exp, args)
More information about the lambda-dev