Know about Scala’s apply() function

--

In this blog post I will explain you one of the confusing feature of Scala for beginners i.e apply() method.

In Scala, classes can be constructed without using new keyword, like

val emp = Person()

The reason for this statement to create object is because of apply() function. Person() is not actually a constructor.

In Scala there are several ways to demo this:

val numbers = List(1,2,3,4,5)

In the above example also we are creating object of list without new keyword.

The rest of this post has been migrated here.

--

--

Naveen - (Founder & Trainer @ NPN Training)
Naveen - (Founder & Trainer @ NPN Training)

Written by Naveen - (Founder & Trainer @ NPN Training)

A software training institute which believes that technology has to be learnt under experienced practitioners — www.npntraining.com

No responses yet