- Loading...
When a boxed value is being used as a simple reference, sometimes reference identity must be preserved.
This means there must be defined scopes where reboxing is not allowed.
AtomicReference<Object> ref = new AtomicReference<Object>(); Object c1 = Complex.valueOf(1, 0); Object c2 = Complex.valueOf(0, 1); ref.set(c1); boolean ok; ok = ref.compareAndSet(c1, c2); assert(ok);
The assertion can fail if reboxing of c1 is allowed in this code.