Sponsored Links

Ad by Google
The Scala stands for "Scalable Language" is a pure object oriented with fully supported functional programming language. Scala is concise and very much comparable with Java programming language.
The origin of Scala is mix of many languages like Java, C#, C++, Haskell etc.
Scala runs on JVM(Java Virtual Machine), Scala source code compiled into byte code similar to Java, you can easily mix Java code inside Scala or you can use Java libraries inside your Scala project. Although Scala is very much similar to Java but still it has some differences which makes it more demanding in a very short period of time unlike other languages. Here is detailed differences between Scala and Java Scala Vs Java

We have already seen how many types of variables are available in Scala and when to use them with step by step guide at here. And, In this article, I am going to show you a simple example of lazy evaluation in Scala.
Lazy evaluation Scala
lazy val are calculated on demand when they accessed for the first time.
scala> lazy val num=10
num: Int = <lazy>
Here it's printing lazy value instead of num value 10, because of lazy val, lazy val calculated only when they accessed, but if you remove the lazy keyword, than, it will print the num value as 10 without even printing them, below is example of non-lazy.
scala>  val mynum=10
mynum: Int = 10

Sponsored Links


Post a Comment