Consider following object,
object A {
def setX(x:Int) = {
val x1 = x
}
def getx() = x1
}
If I create val x1 inside setX that’s scope will be the method setX. what I really want to do is create a val outside the method and assign the value inside the method. Is it impossible without using var, or is there any way to do it?
Please send me an example if you can.
That is sort of the difference between
val(“readonly”) andvar.So no: not possible.
If the problem (not the desired solution) is explained more, there might be alternative approaches.
Happy coding.