import org.apache.commons.lang.ObjectUtils;
public class MainClass {
public static void main(String[] args) {
//Create ObjectUtilsTrial instance
MyClass one = new MyClass();
MyClass two = one; //Same Reference
MyClass three = new MyClass(); //New Object
MyClass four = null;
//four is null, returns DEFAULT
System.out.print("1) If null return DEFAULT >>>");
System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT"));
}
}
class MyClass{
public String toString() {
return "toString Output";
}
}
1) If null return DEFAULT >>>DEFAULT
Download: CommonLangObjectUtils.defaultIfNull.zip( 199 k)