What's the difference between val
and var
?
- A
val
variable can not have it's value changed, but avar
variable can.
What's the deal with implicit val
?
- Marking a value as
implicit
allows it to be used by functions that accept implicit parameters.
def fn(x: Int)(implicit y: Boolean) = if(y) x else - x
fn(1)(true) // returns 1
implicit val b = false
fn(1) // returns -1 using b as the argument for the implicit argument