Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to avoid lots of "if (obj != null)" in Java code? [duplicate]

Possible Duplicate:
How to avoid “!= null” statements in Java?

Share your thoughts..

like image 732
The Student Avatar asked Jul 29 '10 14:07

The Student


1 Answers

A first answer is to always return empty Lists, Sets, Arrays instead of null for method returning this kind of objects. Item 43 of Effective Java second edition from Joshua Bloch

like image 105
Manuel Selva Avatar answered Oct 05 '22 04:10

Manuel Selva