What is Lazy val in Scala?

0 votes
Can anyone explain what Lazy val in Scala with a example?
Jul 29 in Apache Spark by Ishaan
43 views

1 answer to this question.

0 votes

Hey,

Scala executes a val when we define it, but executes a lazy val only when we access it the first time. We declare it using the keyword lazy:

scala> lazy val x=7

x: Int = <lazy>

scala> lazy val x=2+3

x: Int = <lazy>

Where eager evaluation is at compile-time, lazy evaluation is at run-time.

answered Jul 29 by Gitika
• 25,420 points

Related Questions In Apache Spark

0 votes
1 answer

What is the advantage of having immutability in design for Scala programming language?

Hi, Scala uses immutability by default in most ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,420 points
46 views
0 votes
1 answer

What is ofDim in Scala?

Hey, ofDim() is a method in Scala that ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,420 points
97 views
0 votes
1 answer

How is Val different from var in Scala?

Hey, In this language, val is a value and var is ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,420 points
41 views
0 votes
1 answer

What is exception propagation in Scala?

Hi, When a function experiences an exception, it ...READ MORE

answered Jul 25 in Apache Spark by Gitika
• 25,420 points
32 views
+1 vote
1 answer
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,800 points
3,579 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,800 points
455 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
18,435 views
0 votes
1 answer

What is Lazy evaluated in Spark?

Hi, If you execute a bunch of programs, ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,420 points
86 views
0 votes
1 answer

What is “Unit” and “()” in Scala?

Hey, Unit is a subtype of scala.anyval and ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,420 points
49 views