Some notes on Elvis and Other Null-Safe Operators
Schulz, Stefan
schulz at e-Spirit.de
Mon May 18 02:51:05 PDT 2009
Joseph D. Darcy wrote:
> Mark Mahieu wrote:
> > 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
Just as a side note: while such a library based solution for elvis is formally possible, without some closure like construct, the advantage of evaluating the RHS expression on demand only will be lost.
Cheers, Stefan
More information about the coin-dev
mailing list