Collection of bad coding practices

Posts Tagged ‘null

Null returned from a method returning a collection or an array

with 6 comments

Null should never be returned from a method returning a collection or an array. Instead return a empty array (a static final empty array) or one of the empty collections (e.g. Collections.EMPTY_LIST assuming the client should not be modifying the collection).

(submitted by Rand McNeely)


Written by Alex

November 11, 2009 at 5:10 pm

Posted in Collections

Tagged with , ,

‘equals()’ does not check for null argument

with 7 comments

If you override equals() method in your class, always check if an argument is null. If a null value is passed, equals() must unconditionally return false (no NullPointerException should be thrown!).

Read the rest of this entry »

Written by Alex

November 22, 2007 at 2:08 pm

Posted in Objects

Tagged with , ,