2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-09 07:10:36 +00:00
cheat.sheets/sheets/_scala/Variables

22 lines
312 B
Plaintext
Raw Normal View History

// variable
// mutable
2017-05-28 21:10:53 +00:00
var x = 5
// value
// immutable, evaluated once during compilation
2017-05-28 21:10:53 +00:00
// GOOD
val x = 5
// BAD
x = 5
// lazy value
// immutable, evaluated once but only when called
lazy val x = 5
// definition
// immutable, evaluated every time it is called
def x = 5
2017-05-28 21:10:53 +00:00
// explicit type
val x: Double = 5