Community
Participate
Working Groups
A common pattern I've encountered could be termed derived nullable. Given a function f(A) returning B, I have a dilemma in declaring A and B as @Nullable or @NonNull when I want the behavaiour non-null A => non-null B null A => null B @Nullable B f(@Nullable A) gives me no checking at all @NonNull B f(@NonNull A) prohibits null propagation Suggestion: @DerivedNullable B f(@Nullable A a) where @DerivedNullable is equivalent to @NonNull if all parameters of f are known to be non-null @Nullable otherwise Or more powerful/complex @DerivedNullable(a) B f(@Nullable A a) where the @DerivedNullable arguments provide a conjunction of non-null requirements.
That's an interesting one! Let me see, if we were able to say this: <N extends Nullness> @N B f(@N A a) (where @NonNull and @Nullable would both extend @Nullness). wouldn't that meet your requirement? While neither javac8 nor ecj8 accept such code, interestingly, they reject it for different (incorrect?) reasons. Before discussing a solution in Java7- land, let me first check, whether anything along the sketched lines is _intended_ to work in Java8 (though I guess it would not).