Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.cantaa.util;

Utilities around Objects

Author(s):
Hans Lesmeister
 
 public class ObjectUtil {
   
Compares 2 Objects on equality, but with null-safety

Parameters:
a 1. Object (can be null)
b 2. Object (can be null)
Returns:
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