Safe navigation operator
eaftan at google.com
Wed Jan 16 19:26:29 UTC 2019
While it's admirable to advocate that developers avoid nulls, the reality
is that nulls are present in real-world code and are currently painful to
code around. Even languages like Kotlin and Swift that have null-checking
built into the type system provide this operator, acknowledging that it's
not realistic for code to avoid nulls altogether.
I'm not arguing that the safe navigation operator is good or bad, I haven't
used it enough to form an opinion. Just pointing out that any rationale
that depends on Java code not using nulls is not realistic.
On Wed, Jan 16, 2019 at 9:03 AM Remi Forax <forax at univ-mlv.fr> wrote:
> Hi Jeyvison,
> The nullsafe navigation has been proposed as part of the project Coin (for
> Java 7).
> As far as i remember, it has been rejected because it allows to seamlessly
> propagate null in the code which is not the good solution, methods should
> you never return null, so you should not have to propagate it.
> Since then, Java 8 has introduced Optional which force the user of a
> method that return Optional to take care of the fact that the method can
> return no result.
> The method Optional.map() (or flatMap()) is the equivalent of the nullsafe
> navigation syntax.
> ----- Mail original -----
> > De: "Jeyvison Nascimento" <jeynoronha at gmail.com>
> > À: "amber-dev" <amber-dev at openjdk.java.net>
> > Envoyé: Mercredi 16 Janvier 2019 16:13:02
> > Objet: Safe navigation operator
> > Hi Folks :)
> > Not sure if this is the best mail list to start it but I'd like to start
> > discussion about safe navigation operator (i.e "?." in Kotlin) in java.
> > Not sure if this was already talked about but if it wasn't I think it's
> > something worth to investigate and explore.
> > What do you people think about it?
> > --
> > Jeyvison Nascimento
More information about the amber-dev