If I have defined a variable b val b:B
. Is it possible to print the value of b
each time b is assigned to a new value. Like the code below:
case class B(name:String) {
}
var b = B("123")
b = B("xxx")
println(s"b is changed to $b")
b = B("xxJJx")
println(s"b is changed to $b")
I hope the code println(s"b is changed to $b")
be hidden in some sort of macro when I create B
or b
, like:
var b = macro_wrap(B("123"))