Reputation: 73
I'm using an older version of scala 2.7.5
When i try to do computations like this,
var x = 100
var x = x%1000
I get a
error: recursive variable x needs type
Is there a work around? why do i get this error?
Upvotes: 5
Views: 5786
Reputation: 294
For anyone still wondering, in this particular case Kim Stebel already wrote the correct solution.
If you just wanted to solve the type error for var x = x%1000
the solution would be simple like this: var x:Int = x%1000
(which equals to 0, because of the default int value of the JVM, this is a really weird recursive expression though)
Upvotes: 0
Reputation: 42037
You're declaring the variable twice rather than just changing its value. Instead, do
var x = 100
x = x%1000
Upvotes: 12