Settings

Theme

Null is your friend, not a mistake

medium.com

2 points by raytracer 7 years ago · 1 comment

Reader

adrianmsmith 7 years ago

Ideally, as the article suggests, you should use a language which supports null and not-null types, with compile errors if you call a method on a type that might be null before checking to make sure it’s not null.

However, if you’re stuck with Java, which doesn’t do that, you can annotate your types with @Nonnull and @CheckForNull. (At least) SpotBugs and IntelliJ respect such annotations.

I have done this to every parameter type, return type, and instance variable on a 15 KLOC codebase and it’s been a great success.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection