src/main/java/org/jboss/util/Objects.java
public static <T> T deref(final Object obj, Class<T> expected)
   {
      Object result = deref(obj);
      if (result == null)
         return null;
      return expected.cast(result);
   }
public static <T> T deref(final Object obj, Class<T> expected)
   {
      Object result = deref(obj);
      if (result == null)
         return null;
      return expected.cast(result);
   }
Dereference an object

@param <T> the expected type
@param obj the object or reference
@param expected the expected type
@return the object or null