Author: limpbizkit
Date: Thu Jan  1 13:51:48 2009
New Revision: 770

Added:
    wiki/UseNullable.wiki

Log:
Created wiki page through web user interface.

Added: wiki/UseNullable.wiki
==============================================================================
--- (empty file)
+++ wiki/UseNullable.wiki       Thu Jan  1 13:51:48 2009
@@ -0,0 +1,18 @@
+=Use @Nullable=
+To eliminate `NullPointerExceptions` in your codebase, you must be  
disciplined about null references. We've been successful at this by  
following and enforcing a simple rule:
+  _Every parameter is non-null unless explicitly specified._
+The [http://code.google.com/p/google-collections/ Google Collections  
library] has simple APIs to get a nulls under control.  
`Preconditions.checkNotNull` can be used to fast-fail if a null reference  
is found, and `...@nullable` can be used to annotate a parameter that permits  
the `null` value:
+{{{
+import static com.google.common.base.Nullable;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class Person {
+  ...
+
+  public Person(String firstName, String lastName, @Nullable Phone phone) {
+    this.firstName = checkNotNull(firstName, "firstName");
+    this.lastName = checkNotNull(lastName, "lastName");
+    this.phone = phone;
+  }
+}}}
+*Guice forbids null by default.* It will refuse to inject `null`, failing  
with a `ProvisionException` instead. If `null` is permissible by your  
class, you can annotate the field or parameter with `...@nullable`. Guice  
recognizes any `...@nullable` annotation, like  
[http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Nullable.html
  
com.google.common.base.Nullable] or  
[http://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax/annotation/Nullable.java?r=24
  
javax.annotation.Nullable].

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to