Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.cantaa.util;

Utilities around Objects

Hans Lesmeister
 public class ObjectUtil {
Compares 2 Objects on equality, but with null-safety

a 1. Object (can be null)
b 2. Object (can be null)
if both object are null then true, else a normal equals is performed (of course on a non-null object)
   public static final boolean secureEquals(Object aObject b)
       if ((a != null) && (b != null))
           return a.equals(b);   // Standard equals if both are non-null
       if ((a == null) && (b == null))
           return true;   // They are equal if both are null
       return false;   // if just one is null then they never equals
New to GrepCode? Check out our FAQ X