« Return to Thread: Reassignment to Val

Re: Reassignment to Val

by Randall Schulz :: Rate this Message:

Reply to Author | View in Thread

On Monday July 6 2009, Joob wrote:
> Hello everyone,
>
> I'm new to scala so please don't take anything for granted with me :)

Well, you see, computers are these electronical machines that we use to
make like difficult for others...


> Anyway,
> I'm getting this error "Reassignment to val"

A "val" is an "immutable" record of a value. By immutable we mean it
cannot be reassigned. There are lots of positive virtues to defining
programs in terms of immutable data, but it's sometimes challenging to
do so. Unlike Haskell, which is considered a "pure" functional language
that strictly forbids such "side-effects" and "mutable state," Scala
doesn't force you to use immutable data. When you feel the need to be
able to reassign the value in a field or local variable (or function /
method parameter), you can use a "var" instead of a val.


> ...
>
> Can anyone help me ?

Anything could happen...


Randall Schulz

 « Return to Thread: Reassignment to Val