Null-safe navigation operator (and elvis operator)

Joe Darcy joe.darcy at oracle.com
Tue Jul 9 21:41:59 UTC 2019


Hello Janis,

We've been aware of the null safe navigator operator, sometimes referred 
to as the Elvis operator, no later than the Project Coin call for 
proposals back in February 2009:

https://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000047.html

To date, we have chosen not to pursue this change.

Cheers,

-Joe

On 7/9/2019 6:08 AM, Janis Schöck wrote:
>
> Hello compiler-dev List,
>
> I am trying to assert, whether my idea (which is not actually original 
> it appears) is valuable for Java.
> Apparently kotlin already features the following (null safe navigation 
> operator):
>
> // returns null if...
> // - foo() returns null,
> // - or if foo() is non-null, but bar() returns null,
> // - or if foo() and bar() are non-null, but baz() returns null.
> // vice versa, return value is non-null if and only if foo(), bar() 
> and baz() are non-null
> foo()?.bar()?.baz()
>
> In that same context, if an expression would evaluate to null, but a 
> primitive type is required, kotlin can
> fall back on a default, or evaluate an alternate expression.
>
> val  name:  String  =  maybe  ?:  "stranger"
>
> Independently of kotlin, I think null safe accessing seems to be a 
> valuable language feature. Since I did not
> know kotlin had this when I started, I put it into a JEP/JSR format to 
> collect feedback on. Since I am new to
> this list, maybe the primary question: Do I just write up the entire 
> JEP-plain text here, or will this just bother
> people, as it is a lot of text, and probably will mess up bulked mails?
>
> Secondary question: Is this the correct list to write to, or is this 
> better addressed at the amber-project list?
>
> Thank you in advance,
> Janis Schöck
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20190709/f696d70d/attachment-0001.html>


More information about the compiler-dev mailing list