Null-safe navigation operator (and elvis operator)
Janis Schöck
janis at schoeck-netz.de
Tue Jul 9 13:08:12 UTC 2019
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/076e816b/attachment.html>
More information about the compiler-dev
mailing list