We are going to start this tutorial by explaining the diferent ways in which we can name variables in Scala, by using the keyword var
or val
.
var
denotes that it is a var
iable, and as such, its value can change in different points of our program. For example:
var myNewVariable = 4
... // some time later...
myNewVariable = 40
As we can se, we are using the same variable to hold two different values 4
and 40
.
On the other hand, a val
defines a val
ue, which is something that will not change in the entire life of the application or real life. For example, the value 4 will never change, since it would make no sense that it meant something diffent.
val gravity = 9.81
If you ever try to modify a val
ue, the compiler will throw and error and abort compilation.
Congratulations @egosum! You received a personal award!
Click here to view your Board of Honor
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @egosum! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit