Make Null a subclass of AnyVal under -Yexplicit-nulls

You can make the same argument about JavaScript. And in JavaScript, null has type Null which is considered a primitive type.

No. Explicit-nulls should make it so that no NPEs are thrown at all :slight_smile: In the same way that our existing type system ensures that no ClassCastExceptions are thrown at all (as long as one doesn’t perform an incorrect asInstanceOf/nn, as usual).

This change is only proposed in the context of -Yexplicit-nulls, which is experimental. Therefore, breaking changes don’t count.

It seems I need to repeat this every 10th reply: if you don’t provide a concrete use case for a T <: AnyVal bound, it’s not worth discussing what would happen to such code.

Or: don’t add NonNull. Wait and see if it’s actually missing before introducing it → no backward compat lockdown.

It turns out this is not true. There is already no straightforward way to implement NonNull. See "MINUS_NULL" and the future of explicit nulls - #25 by sjrd . And therefore, it can’t be argued that it will worsen Java interop.

1 Like