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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -