Proxy equality

Proxies can be tested whether they represent the same, remote object (isSameAs()). Proxies are functionally transparent with respect to equality, i.e. equals(Object) and hashCode() behaves the same whether applied to proxies and their underlying representation.

However, if the proxy connection breaks, both methods will become unusable (i.e. throw exceptions). Hence, proxy objects should not be stored in containers that continuously use those methods (e.g. java.util.HashMap).

The following optimisations are possible without affecting semantics:

  1. the result of hashCode() can be cached if the implementation object does not override Object.hashCode().
  2. equals(Object) can be reduced to isSameAs() on the proxies if the implementation object does not override Object.equals(Object).



Ulf Leonhardt 2001-08-16