What are the chances of getting exactly the same object reference twice
<p>I sometimes assume that if <code>oldObject != newObject</code> then the object has changed - which seems a fair assumption in most cases but is it truly a bad assumption?</p>

<p>In short, under what situation could the following code print "Same!"?</p>

<pre><code>static WeakReference&lt;Object&gt; oldO = null;
...

Object o = new Object();
oldO = new WeakReference(o);

// Do some stuff with o - could take hours or even days to complete.
...

// Discard o (or let it go out of scope).
o = null;

// More stuff - could be hours or days later.
...
o = new Object();

// Later still.
if ( o == oldO.get() ) {
  System.out.println("Same!");
}
</code></pre>

<p>I realise that this is indeed remotely possible because an object reference is essentially the memory address of the object (or could be in some JVM). But how likely is it? Are we talking decades of run-time before it actually happens?</p>

<p><strong>Added</strong></p>

<p>My apologies - please assume that <code>oldO</code> is some form of <code>weak</code> reference that does not stop it from being collected. Perhaps it is <code>Weak</code> as the code (now) suggests or the reference is store in a database or a file somewhere.</p>
