Is it possible to declare a global variable in this way?
if i run this snippet, i will encounter an error
object Test {
val value -> error on this line for declaration issue
def run() {
value = ...
}
def main(args: Array[String]) {
run()
}
thanks in advance.
You could in theory do it using a Trait. I'm not sure this is what you need though.
It would look like this:
trait MyTestTrait {
val value: String
}
object MyTest extends MyTestTrait {
val value = "yo!"
def run = println(value)
}
No, that's not possible. You should do this:
object Test {
val value = ...
}
Since your run()
function does not take parameters, the contents of value
can also be computed without it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With