| 1. |
What Is The Difference Between “val” And “lazy Val” In Scala? What Is Eager Evaluation? What Is Lazy Evaluation? |
|
Answer» As we discussed in my Basic Scala Interview Questions, “val” means value or CONSTANT which is used to DEFINE IMMUTABLE variables. There are two kinds of program EVALUATIONS:
Eager Evaluation means evaluating program at compile-time or program deployment-time irrespective of clients are using that program or not. Lazy Evaluation means evaluating program at run-time on-demand that means when clients access the program then only its evaluated. The difference between “val” and “lazy val” is that “val” is used to define variables which are evaluated eagerly and “lazy val” is also used to define variables but they are evaluated lazily. As we discussed in my Basic Scala Interview Questions, “val” means value or constant which is used to define Immutable variables. There are two kinds of program evaluations: Eager Evaluation means evaluating program at compile-time or program deployment-time irrespective of clients are using that program or not. Lazy Evaluation means evaluating program at run-time on-demand that means when clients access the program then only its evaluated. The difference between “val” and “lazy val” is that “val” is used to define variables which are evaluated eagerly and “lazy val” is also used to define variables but they are evaluated lazily. |
|