Created
August 1, 2016 06:23
-
-
Save Kuchitama/399d44e0601e164ab99da77a7f95b10d to your computer and use it in GitHub Desktop.
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 Main extends App{ | |
/****************** | |
* val : immutable valuable | |
******************/ | |
val one: Int = 1 | |
println(s"one is ${one}") | |
val two = 2 | |
println(s"two is ${two}") | |
// compile error: type mismatch; | |
// val three: Int = "three" | |
val name = "Kuchitamaaaa" | |
// compile error | |
// val name = "Kuchitama" | |
println(s"name is ${name}") | |
/****************** | |
* var : mutable valuable | |
******************/ | |
var counter = 0 | |
for (_ <- 1 to 5) { | |
counter = counter + 1 | |
println(s"current counter is ${counter}") | |
} | |
/****************** | |
* lazy val | |
******************/ | |
var now = 0 | |
lazy val lazyNow = now | |
println(s"now is ${now}") | |
now = now + 1 | |
println(s"now is ${now}, lazyNow is ${lazyNow}") | |
now = now + 1 | |
println(s"now is ${now}, lazyNow is ${lazyNow}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment