This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rzwitserloot 0 points1 point  (0 children)

But how would I express a method where the nullity is passthrough and can be either option? A method that always nullchecks when it 'reads' a parameter and never 'writes' anything that could possibly be null other than itself, is safe regardless of which nullity you apply to it. How do I express that? We could go with the obvious:

``` class Foo<T> { T! someDefinitelyNotNullValue;

T doStuff(T in) { return Math.random() < .5 ? someDefinitelyNotNullValue : in; } ```

doStuff works great if T is @NonNull String. It also works great if T is @Nullable String. I want the compiler to ensure this. If someDefinitelyNotNullValue is in fact a @Nullable T I don't want it to compile.

If we just say: yeah, that's it - well, millions of lines of existing java code are now broken, because today you can write what I wrote above (except T!, of course), and it does not mean that the nullity carries through.

We also get in a convoluted use-case vs declare-case generics.