public static boolean areEquivalent(Object proxiedObj, Object anotherProxiedObj)
   {
      if (proxiedObj == null && anotherProxiedObj == null)
      {
         return true;
      }
      else if (proxiedObj == null || anotherProxiedObj == null)
      {
         return false;
      }
      else
      {
         Object unproxiedObj = unwrap(proxiedObj);
         Object anotherUnproxiedObj = unwrap(anotherProxiedObj);

         boolean sameClassName = unwrapProxyClassName(unproxiedObj.getClass()).equals(
                  unwrapProxyClassName(anotherUnproxiedObj.getClass()));
         if (sameClassName)
         {
            if (unproxiedObj.getClass().isEnum())
            {
               // Enum hashCode is different if loaded from different classloaders and cannot be overriden.
               Enum<?> enumLeft = Enum.class.cast(unproxiedObj);
               Enum<?> enumRight = Enum.class.cast(anotherUnproxiedObj);
               return (enumLeft.name().equals(enumRight.name())) && (enumLeft.ordinal() == enumRight.ordinal());
            }
            else
            {
               return (unproxiedObj.hashCode() == anotherUnproxiedObj.hashCode());
            }
         }
         else
         {
            return false;
         }
      }
   }
public static boolean areEquivalent ( Object proxiedObj , Object anotherProxiedObj ) { if ( proxiedObj == null && anotherProxiedObj == null ) { return true ; } else if ( proxiedObj == null || anotherProxiedObj == null ) { return false ; } else { Object unproxiedObj = unwrap ( proxiedObj ) ; Object anotherUnproxiedObj = unwrap ( anotherProxiedObj ) ; boolean sameClassName = unwrapProxyClassName ( unproxiedObj . getClass ( ) ) . equals ( unwrapProxyClassName ( anotherUnproxiedObj . getClass ( ) ) ) ; if ( sameClassName ) { if ( unproxiedObj . getClass ( ) . isEnum ( ) ) { Enum < ? > enumLeft = Enum . class . cast ( unproxiedObj ) ; Enum < ? > enumRight = Enum . class . cast ( anotherUnproxiedObj ) ; return ( enumLeft . name ( ) . equals ( enumRight . name ( ) ) ) && ( enumLeft . ordinal ( ) == enumRight . ordinal ( ) ) ; } else { return ( unproxiedObj . hashCode ( ) == anotherUnproxiedObj . hashCode ( ) ) ; } } else { return false ; } } }
This method tests if two proxied objects are equivalent.

It does so by comparing the class names and the hashCode, since they may be loaded from different classloaders.