Created
October 27, 2018 04:21
-
-
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
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
#!/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