PROPOSAL: Null safe type system

Brian Goetz brian.goetz at oracle.com
Mon May 16 16:52:42 UTC 2022


> 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