javadoc.com.google.common.collect.ForwardingObject.html Maven / Gradle / Ivy
ForwardingObject (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.collect
Class ForwardingObject
java.lang.Object
com.google.common.collect.ForwardingObject
- Direct Known Subclasses:
- ForwardingCache, ForwardingCollection, ForwardingExecutorService, ForwardingFuture, ForwardingIterator, ForwardingMap, ForwardingMapEntry, ForwardingMultimap, ForwardingService, ForwardingTable
@GwtCompatible
public abstract class ForwardingObject
- extends Object
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
Collections.unmodifiableCollection(java.util.Collection extends T>)
. 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.
- Since:
- 2.0 (imported from Google Collections Library)
- Author:
- Mike Bostock
Constructor Summary | |
---|---|
protected |
ForwardingObject()
Constructor for use by subclasses. |
Method Summary | |
---|---|
protected abstract Object |
delegate()
Returns the backing delegate instance that methods are forwarded to. |
String |
toString()
Returns the string representation generated by the delegate's toString method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
ForwardingObject
protected ForwardingObject()
- Constructor for use by subclasses.
Method Detail |
---|
delegate
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.
toString
public String toString()
- Returns the string representation generated by the delegate's
toString
method.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.