Menu

  • Home
  • Archives
  • Tags
  • RSS
July 31, 2014

scala var

Using all three (val, var, `d

ef), I initialize, and then attempt to reassign. Only var` succeeds (as it should), but the other two fail in different ways.




scala> val x = 6

x: Int = 6



scala> x = 7

<console>:11: error: reassignment to val

       x = 7

         ^



scala> var x = 6

x: Int = 6



scala> x = 7

x: Int = 7



scala> def x = 6

x: Int



scala> x = 7

<console>:11: error: value x_= is not a member of object $iw

       x = 7

       ^



Deceptively similar at first, but I suppose you get used to it. Also, what the heck is $iw ?? (I'm guessing it's an internal Java representation of the Int class)


Tags: old-post

« possibly unevaluated variables up and running with scala »

Copyright © 2020 Agam Brahma

Powered by Cryogen