I make everything final and annotate every return type and parameter as either @NotNull or @Nullable. Some people say it's too verbose, but it has cut down the amount of mistakes I make by probably an order of magnitude.
Or I just use Kotlin and get all of this and more for free. :)
Exactly. A Lint warning is not as good as a compiler error like you get with Kotlin, but it's the best thing that we'll get in Java, and if you're paying attention, you still have almost no excuse for NPEs. The only exception I can really think of is if you call a library function that either isn't annotated, or that your IDE can't infer the nullity for. Those are always a huge bummer. :(
5
u/Paradiesstaub Nov 26 '16
How about making everything possible
final(class, method, variables).