1. Constant definition: Val
Val is similar to the final variable in Java. Once initialized, Val can no longer be assigned a value
Val megs = "Hello World"
2. Definition of variable: var
var is like a non-final variable in Java that can be assigned multiple times within its declaration period
var spark:string = "I am Big Data"
var spark:string = "I Am"
Table key additions and hints are supported in the interpreter
3. Variable type inference:
When assigning an initial value to a variable, the Scala compiler can calculate the variable type based on the value assigned to it. This is known as variable type inference. Therefore, the declaration of these variables can be written as follows:
var=ten; ="Hello, scala!" ;
here, by default, MyVar is of type int and will be set to Myval as a string variable .
Original Scala Learning: About variables (Val,var, type inference)