Skip to content

Instantly share code, notes, and snippets.

@dsugden
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsugden/b0ded410c5977e6cc13e to your computer and use it in GitHub Desktop.
Save dsugden/b0ded410c5977e6cc13e to your computer and use it in GitHub Desktop.
Example of dangers of mutation
object MutableBad{
class MDate(dayIn:Int){ var day = dayIn }
type Task = Int
def scheduleTask(task:Task,date:MDate) = ???
var d = new MDate(22)
scheduleTask(1, d) // some other code block has a reference to d, changing d would be bad
d.day = 33 // WAT??, I should have made a defensive copy of d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment