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:
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
DeterministicObject
public DeterministicObject()Create a DeterministicObject.
-
-
Method Details