Sunday, May 7, 2017

Avoiding null's -> becoming better programmer ;-)

From some time all my IntelliJ's are showing usage of null as error.
I created inspection (if you want you may download it and add to your IntelliJ) which cause that my code which is using null looks like this:


This caused that I started to use Optional more often, and even started to read InputStreams different than earlier ;-)

Mainly because of this that when I'm on autopilot and put null into code, this is marked as error and I must start to think about better solution.

Of course, sometimes null is needed and helpful, but it is also very error prone.
Each usage of null means being closer to moment when you will return null, and this will lead to NullPointerException in less expected moment.


Similar postsbeta
Coding time means often waiting/reading time ;-)
OpenOffice.org2GoogleDocs 1.0.4
I just love JSON ;-)
OOo2GD 2.1.1 is ready :-)
Yep, tablet may replace computer in most of cases...

No comments:

Post a Comment