- Direct Known Subclasses:
@GwtCompatible public abstract class ForwardingObject extends ObjectAn abstract base class for implementing the decorator pattern. The
delegate()method must be overridden to return the instance being decorated.
This class does not forward the
equalsmethods through to the backing object, but relies on
Object's implementation. This is necessary to preserve the symmetry of
equals. Custom definitions of equality are usually based on an interface, such as
List, so that the implementation of
equalscan cast the object being tested for equality to the custom interface.
ForwardingObjectimplements no such custom interfaces directly; they are implemented only in subclasses. Therefore, forwarding
equalswould break symmetry, as the forwarding object might consider itself equal to the object being tested, but the reverse could not be true. This behavior is consistent with the JDK's collection wrappers, such as
Collections.unmodifiableCollection(java.util.Collection<? extends T>). Use an interface-specific subclass of
ForwardingObject, such as
ForwardingList, to preserve equality behavior, or override
toStringmethod is forwarded to the delegate. Although this class does not implement
Serializable, a serializable subclass may be created since this class has a parameter-less constructor.
- 2.0 (imported from Google Collections Library)
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
toString()Returns the string representation generated by the delegate's