Last active
August 29, 2015 14:02
-
-
Save dsugden/b0ded410c5977e6cc13e to your computer and use it in GitHub Desktop.
Example of dangers of mutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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