5

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?

3
  • what are you trying to achieve there? you're declaring a new variable and initializing it with reference to itself? if shouldn't allow you to do that Commented Aug 10, 2015 at 14:11
  • @KimStebel please see edit Commented Aug 10, 2015 at 14:11
  • For me, in addition to the error you show, it also gives the error "x is already defined as variable x" Commented Aug 10, 2015 at 14:29

2 Answers 2

12

You're declaring the variable twice rather than just changing its value. Instead, do

var x = 100
x = x%1000
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.