Package org.plumelib.util
Class DeterministicObject
java.lang.Object
org.plumelib.util.DeterministicObject
This is a deterministic version of the
Object class. To remove one source of
nondeterminism from your program, do not instantiate the Object class, as in new
Object(); instead do new DeterministicObject().
This class differs from Object in that it overrides hashCode(). Any use of
Object.hashCode() is nondeterministic because the return value of Object.hashCode()
depends on when the garbage collector runs. That nondeterminism can affect the iteration order of
HashMaps and HashSets, the output of toString(), and other behavior.
To implement similar functionality for other classes, see UniqueId.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final AtomicIntegerThe number of objects created so far.(package private) final intThe unique ID for this object. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
counter
The number of objects created so far. -
uid
final int uidThe unique ID for this object.
-
-
Constructor Details
-
DeterministicObject
public DeterministicObject()Create a DeterministicObject.
-
-
Method Details