Добавить
Уведомления

Scala Interview Question: Val vs. Var - Understanding Immutability and Mutability

Val and var are the two keywords used to define Scala variables. Var keyword is similar to a variable declaration in Java, whereas Val is slightly different. Once a variable is declared using Val the reference cannot be changed to point to another reference. This functionality of Val keyword in Scala can be related to the functionality of the Java final keyword. To simplify it, Val refers to the immutable declaration of a variable, whereas var refers to the mutable declaration of a variable in Scala. In simple terms, if a variable is val, its value cannot be changed. For var, it is possible to change the value at a later stage.

Иконка канала IT Junction
32 подписчика
12+
20 просмотров
2 года назад
12+
20 просмотров
2 года назад

Val and var are the two keywords used to define Scala variables. Var keyword is similar to a variable declaration in Java, whereas Val is slightly different. Once a variable is declared using Val the reference cannot be changed to point to another reference. This functionality of Val keyword in Scala can be related to the functionality of the Java final keyword. To simplify it, Val refers to the immutable declaration of a variable, whereas var refers to the mutable declaration of a variable in Scala. In simple terms, if a variable is val, its value cannot be changed. For var, it is possible to change the value at a later stage.

, чтобы оставлять комментарии