UnwrappedWeakReference extends WeakReference<T> { @Override public boolean equals(Object obj) { T thisObject = this.get(); if (obj instanceof WeakReference) { obj = ((WeakReference)obj).get(); } if (thisObject == null) { if (obj == null) { return true; } else { return false; } } return thisObject.equals(obj); } UnwrappedWeakReference(T ref); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test @SuppressWarnings("IncompatibleEquals") public void equals() throws Exception { String o = new String(); WeakReference ref0 = new UnwrappedWeakReference(o); WeakReference ref1 = new UnwrappedWeakReference(o); Assert.assertTrue(ref0.equals(ref1)); Assert.assertTrue(ref0.equals(o)); Assert.assertTrue(ref1.equals(o)); }