Hacker News new | ask | show | jobs
by mrighele 2461 days ago
You can try checkerframework [1], which uses annotations to perform extra typechecking at compile time, including nullable/not-nullable checks. Works properly altough it has a few issues: the biggest is that support is still stuck at java 8, and the framework is sometimes not smart enough to see that you already checked if a nullable field is null or not and you can safely use it.

[1] https://checkerframework.org/

1 comments

Annotations don't work for local variables, though. So you only get nullability checking around calling methods and accessing fields, right?
Annotations in general do work for local variables, although this is specified on a per-annotation basis.

If I remember correctly, for example, the @NotNull annotation in javax.validation.constraints cannot be used for a local variable, but the one provided by the checkerframework can.