Wish List: Java Object Replacement
Join the DZone community and get the full member experience.Join For Free
I wish I could replace an object with another of the same type and the myriad references existing to the first one would automatically be redirected.
Obj o1 = new Obj("Red");
ball = o1;
Obj o2 = new Obj("Blue");
map.get("Ball") should return the blue ball.
list should contain blue ball.
ball == o2 should evaluate to true.
We can work around the situation by extra code in Obj using composition and method call redirection. Wouldn’t live be simpler if the support is native?
The security part could be controlled by providing a markable interface or annotation.
Real life examples? Substituting a player. Corporate mergers. Two pools joining to make a bigger pool.
Opinions expressed by DZone contributors are their own.