Some notes on Elvis and Other Null-Safe Operators
Stephen Colebourne
scolebourne at joda.org
Sat Apr 18 03:33:31 PDT 2009
Mark Mahieu wrote:
> Which doesn't seem like much of an improvement, to me. But I keep
> thinking that, in the context of this proposal, a null-safe form of
> the foreach loop might not be so bad:
>
> for (Foo foo :? map?.get(key)) {
> ...
> }
I certainly think thats an interesting idea.
However, having a null list is something that rarely comes up in the
code I write. I think thats because I always return an empty list from
methods and never null (something that is definitely good practice).
Where the null-safe operators come in is in handling object model
structure such as a bean holding an optional value (String/Integer/Date
etcc), or a bean holding another optional bean (person holding optional
spouse). In these cases, holding null to represent the absence of data
is a valid design choice.
Stephen
More information about the coin-dev
mailing list