Skip to content

Instantly share code, notes, and snippets.

@hgbrown
Created October 27, 2018 04:21
Show Gist options
  • Save hgbrown/a49eca95160e9844dc70d9e12f22542f to your computer and use it in GitHub Desktop.
Save hgbrown/a49eca95160e9844dc70d9e12f22542f to your computer and use it in GitHub Desktop.
Demonstrates the dangers of mutability in Kotlin. Why you should prefer val to var
#!/usr/bin/env kscript
var factor = 2
fun doubleIt(n: Int) = n * factor
var message = "The factor is $factor"
factor = 0
println(doubleIt(2))
println(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment