How to access the variable outside of scala match expression?

  Kiến thức lập trình

How to access the variable “test” outside of the scala match expression? even i declare as var, it does not return the updated value for test variable.

val x: Int = 2
var test=null
x match {
    case 1 => {var test=10}
    case 2 => {var test=11}
}
println(test)

LEAVE A COMMENT