java - Why does a final collection still get updated? -
i've code store 2 collections , add event listener (no lambda here - need stick java 7 ;) ).
// rri returnrequestinterface final collection<bigdecimal> selecteditems = rri.getselected(); final collection<bigdecimal> unselecteditems = rri.getunselected(); rri.addinformationchangeeventlistener(new componentinformationchangelistener() { @override public void informationchange(requestchangeevent event) { returnrequestinterface source = (returnrequestinterface) event.getsource(); boolean debug1 = source.getselected().containsall(selecteditems); boolean debug2 = source.getunselected().containsall(unselecteditems); } });
i've debugged , collection correctly setup. contained no objects, since code initialized.
debugging listener (the event fired because item selection made) left me confused. booleans debug1
, debug2
both true because collection selecteditems
, unselecteditems
updated according item selection. so, event source collection contained same items declared final collections (selecteditems
, unselecteditems
).
don't 2 declared final collections have stay are?
final
means variable has been declared final
cannot changed, , class final
cannot inherited from. variables aren't primitive references in java, means 'point' or refer instance of object, not objects themselves.
what referring called immutable object, instance of final class
of fields final
, private
, has no setters.
hope helps clarify.
Comments
Post a Comment