Avoid null if possible

Some argue that allowing null into the API of a class, in the form of possibly-null parameters or return values, should be avoided if possible: If null is allowed for a method, then this should be clearly stated in its javadoc. Some follow the convention that all items are assumed to be non-null unless otherwise specified. Such a convention could be explicitly stated once in the javadoc overview.html.

There is a very common exception to this rule. For Model Objects, which map roughly to database records, it's often appropriate to use null to represent optional fields stored as NULL in the database.

See Also :
Prefer empty items to null ones
Model Objects
Consider wrapper classes for optional data
Would you use this technique?
Yes   No   Undecided   
© 2014 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on September 21, 2013.
Over 2,000,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -