Hi,
Attached is the screenshot of my windows powershell, where I am running Scala.
I have tried assigning different values to the same Val a. which is an integer Val, I could assign different values to the Val a. As per Scala, it will not be possible to assign a different value to a Val which has already assigned a value.--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
scala> val a = 3
a: Int = 3
scala> def b = a
b: Int
scala> val a = 4
a: Int = 4
scala> b
res0: Int = 3
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you very much Oliver.
On Fri, Oct 28, 2016 at 9:57 PM, Oliver Ruebenacker <cur...@gmail.com> wrote:
Best, OliverThese are all different vals. Every time you use the val keyword, you define a new val. Reassignment would be to use without the val keyword like this:Hello,
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> val a = 1
a: Int = 1
scala> a = 2
<console>:12: error: reassignment to val
a = 2
^
The Scala Shell (aka REPL) allows you to define different things of the same name, and then the latest will shadow the earlier ones. This is an artefact of how the Scala Shell works.
On Fri, Oct 28, 2016 at 1:31 PM, jithesh karunakaran <jithe...@gmail.com> wrote:
Hi,
Attached is the screenshot of my windows powershell, where I am running Scala.
I have tried assigning different values to the same Val a. which is an integer Val, I could assign different values to the Val a. As per Scala, it will not be possible to assign a different value to a Val which has already assigned a value.Please help.Respectfully,Jithesh.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.