I quite like the explicit nulls feature, but I’m wondering just how far they can eliminate the need to check function arguments for
For example, if I opt in to
-Yexplicit-nulls and write a library with an API function that accepts a
String argument, do I still need to check that argument for
If someone used my library from a Java program, it seems very plausible that they could pass in a
null. So it seems to me that I should still guard against that condition.
However, I’m not entirely sure how I should do this. If I try to check the argument for
null, then the compiler tells me:
Values of types String and Null cannot be compared with == or !=
Is there a way around this? Or is
-Yexplicit-nulls a feature only intended for self-contained programs?
Or perhaps there’s something in the generated bytecode that does the null check?