Top Description Constructors Methods
com.google.common.collect

public abstract Class ForwardingObject

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.collect.ForwardingTable, com.google.common.util.concurrent.ForwardingFuture, com.google.common.util.concurrent.ForwardingExecutorService, com.google.common.cache.ForwardingCache, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingIterator, com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingMapEntry, com.google.common.collect.ForwardingMultimap
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, java.io.Serializable

An 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 hashCode and equals methods 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 Set or List, so that the implementation of equals can cast the object being tested for equality to the custom interface. ForwardingObject implements no such custom interfaces directly; they are implemented only in subclasses. Therefore, forwarding equals would 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 java.util.Collections#unmodifiableCollection. Use an interface-specific subclass of ForwardingObject, such as ForwardingList, to preserve equality behavior, or override equals directly.

The toString method 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.

Author
Mike Bostock
Since
2.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingObject()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
protected abstract Object
delegate()

Returns the backing delegate instance that methods are forwarded to.

public String
toString()

Overrides java.lang.Object.toString.

Returns the string representation generated by the delegate's toString method.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

ForwardingObjectback to summary
protected ForwardingObject()

Constructor for use by subclasses.

Method Detail

delegateback to summary
protected abstract Object delegate()

Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet#delegate. Concrete subclasses override this method to supply the instance being decorated.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the string representation generated by the delegate's toString method.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override