Skip to content

Instantly share code, notes, and snippets.

@Kuchitama
Created August 1, 2016 06:23
Show Gist options
  • Save Kuchitama/399d44e0601e164ab99da77a7f95b10d to your computer and use it in GitHub Desktop.
Save Kuchitama/399d44e0601e164ab99da77a7f95b10d to your computer and use it in GitHub Desktop.
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