Campbell Ritchie wrote:Some people say there is a performance enhancement in Java® too if you use i++, but what is one clock cycle between friends?
Junilu Lacar wrote:
Baz Edwards wrote:
It's very annoying and probably one of the main downfalls of Java as a language because it means you have to check variables for null everywhere, otherwise you'll get NullPointerExceptions being thrown, which is never a good thing.
In Java 8 there has been some attempt to alleviate the pain ... but it's still a bit of a pain, but one you learn to live with ;)
When you find yourself dealing with that problem too much, then you have to look at the design. For example, if a method that declares an object reference return type like List is returning null, then you have to ask why it does that instead of returning an empty List. If it returns an Object and is returning null, you should ask if it's better to return a Null Object instead. These are just two ways you can create a better API and relieve the client code from having to check for null all the time.