Is scala pure object-oriented programming language??

Knoldus Blogs

Most of the people have question “Is scala pure object oriented programming language??” if yes then what about functions and primitives.
yes scala is pure object oriented language and functions and primitives are also objects in scala.

Functions as an object.

Internally function is nothing its a trait with apply function. Let see a Function1 trait with apply function as follows

trait Function1[A,B]{
def apply(x:A):B

Above trait shown its take one parameter as type A and return value of type B so its make a function of type Int => Int = <function1>

if we make a annoynomous function as below

val f=(x:Int)=>x*x

internally it would be

val f=new Function1[Int,Int]{
def apply(x:Int)=x*x

And when we call the function internally its call apply function of the trait
Like,if we call above function like below


internally it will call apply function of the trait


and when we make…

View original post 161 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s