Why is explicit JEP 8303099 nullness not strict?
Brendan McCarthy
brendan at sidecourt.com
Sat Jun 14 00:32:27 UTC 2025
Question on https://openjdk.org/jeps/8303099 "JEP draft: Null-Restricted
and Nullable Types (Preview)":
Why is a narrowing conversion from X? to X! a compiler warning rather
than compiler error?
I fully appreciate the need to avoid any sort of breaking errors when
nullness is adapted on only one side of a two-party relationship. However,
if a library goes out of its way to declare
static void doSomething(String! foo) {...}
A caller shouldn't be allowed to explicitly contradict it with:
String? x = ...
YourClass.doSomething(x)
This is a clear clash of intents. If the caller didn't want to bother with
nullness operators then they wouldn't have added them in the first place.
Much more useful (for me anyway) for the compiler to stop the mistake
immediately.
I've seen a few Valhalla youtube updates as well as Reddit threads
including one where Brian Goetz suggested that would break source or binary
compatibility, but I fail to see how breakage applies in this scenario.
What am I missing?
Thanks in advance for any clarification.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250613/353bf0de/attachment.htm>
More information about the valhalla-dev
mailing list