PROPOSAL: Null safe type system

Alessandro Autiero alautiero at gmail.com
Mon May 16 20:24:07 UTC 2022


Can you think of any issues with the approach described in this
conversation(synthetic null checks)? Perhaps I should write a second
proposal based on this idea instead?

The only issue that I could find when testing this approach against the
points brought up previously by yourself and other readers is that if
String! is erased to String I don't see how a runtime operator such as
instanceof could tell a String! and String? apart. We could add a check
using the compiler, and that's what Kotlin does for example, but that feels
like "cheating" the operator if that makes sense.

Il giorno lun 16 mag 2022 alle ore 18:52 Brian Goetz <brian.goetz at oracle.com>
ha scritto:

>
> > My proposal to leverage Optional was in fact to make this feature feel
> > comfortable with everyone, especially considering that this wrapper has
> > been part of the language for quite a while now and has seen considerable
> > use, also in JDK libraries(see the new HTTP API for example). It's clear
> > though from the points you raised and others that were raised in a
> previous
> > conversation that this approach is far from ideal.
>
> FWIW, this is a common pattern: we observe something that can be
> improved, see it is a big job, and then try to make the job smaller by
> leveraging something we already have, even if its not a great fit.  The
> lesson of past attempts to do this is "if its worth doing, its worth
> doing right -- and that might mean you don't do it -- and that has to be
> OK."
>
> > What do you think
> > though about my proposal to use the module system to make this type
> system
> > opt-in and the other operators that I suggested?
>
> The module system may have a role to play, in identifying boundaries
> where we assert "this module is fully null-aware" vs "this module has
> legacy nullity" (which would affect type checking), and possibly even in
> setting defaults (our C# friends have explored this, where in some
> modules, the default nullity is flipped, and enforcement applied at the
> boundaries.)
>
> The null-aware operators are something that can be considered when all
> types have a nullable projection (i.e.,, `T?` is total on types.)
> They've been discussed a thousand times (and the last 998 times have not
> added anything new to the discussion), so for now, this is something to
> leave for future consideration.
>
>


More information about the amber-dev mailing list