Some notes on Elvis and Other Null-Safe Operators
Joseph D. Darcy
Joe.Darcy at Sun.COM
Thu May 14 22:42:01 PDT 2009
Mark Mahieu wrote:
> Below are a few observations I compiled while building and testing
> the prototype for Elvis and friends, in case they're of interest.
> They are in note form and fairly random order, so please shout if
> anything isn't clear.
>
> Mark
>
>
> --------
>
>
> Elvis operator can be approximated as a library method:
>
> static <T> T elvis(T t1, T t2) { return t1 != null ? t1 : t2; }
>
> In a core-libs round table recording (at http://mail.openjdk.java.net/
> pipermail/core-libs-dev/2009-April/001406.html) the possibility of
> adding core library methods for common null-handling tasks is
> mentioned, such as throwing a standard exception if a supplied
> argument is null (presumably similar to methods in
> com.google.common.base.Preconditions). Is it reasonable to implement
> the Elvis operator as a language change but other null-handling
> facilities as library changes?
>
A belated reply, in general and for null handling in particular,
addressing the problem with libraries is preferable to addressing the
problem with a language change.
-Joe
More information about the coin-dev
mailing list