The Artima Developer Community
Sponsored Link

Programming in Scala Forum
How immutable set's "+=" operation works ?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Suraj Gharat

Posts: 1
Nickname: suraj623
Registered: Feb, 2016

How immutable set's "+=" operation works ? Posted: Feb 10, 2016 8:32 AM
Reply to this message Reply
Advertisement
var jetSet = Set("Boeing", "Airbus")
jetSet += "Lear"

In the above code snippet, set "jetSet" is an immutable set, and the second statement creates a new set with values from "jetSet" and a string "Lear", and then reassigns that new set to variable "jetSet".

Now if we consider the operation "+=" is actually a method call on a set instance "jetSet", with one string parameter, I dont understand how a class method call can change the "jetSet" variable, since its being called on that same variable and it is not an assignment statement either!!!

Please help me understand this.

Topic: 3rd edition plans? Previous Topic   Next Topic Topic: How to fix the cross-compile error when using SuperSafe?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use