Skip to content
alexradzin edited this page Jun 11, 2012 · 5 revisions

Add dependency to your pom.xml

	<dependency>
	  <groupId>com.github.alexradzin</groupId>
	  <artifactId>safechain</artifactId>
	  <version>0.1-SNAPSHOT</version>
	</dependency>

If you are not using maven download jar from repository and put it to the classpath.

Add static import:

import static com.safechain.NullSafeUtil.$;

You are ready to use SafeChain. The following code will print null although p.getSpouse() returns null and threfore invocation of getFirstName() is expected to throw NullPointerException.

	Person p = new Person();
	String spouseFirstName = $(p).getSpouse().getFirstName();
	System.out.println(spouseFirstName);

If object p is used directly without wrapping the following call throws NullPointerException as expected:

	String spouseFirstName2 = p.getSpouse().getFirstName();

Clone this wiki locally