r/androiddev • • Nov 26 '16

Effective Java for Android (cheatsheet)

https://medium.com/rocknnull/effective-java-for-android-cheatsheet-bf4e3433889a
223 Upvotes

49 comments sorted by

View all comments

5

u/Paradiesstaub Nov 26 '16

How about making everything possible final (class, method, variables).

14

u/shadowdude777 Nov 26 '16

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. :)

11

u/drabred Nov 26 '16

I've been doing this. Now (in Java) I assume not-nullability and only use @Nullable where needed. It's not that tedious this way.

4

u/shadowdude777 Nov 26 '16

That's not a bad idea. I find myself using @NotNull WAY more often than @Nullable so maybe only annotating the latter is a good way to cut down on verbosity while also getting the same linter warnings.

Though I think it still might be worth annotating parameters as @NotNull because I believe you can still pass @Nullable values to non-annotated params without triggering the lint warning, right?