Is scala pure object-oriented programming language??

HackT0Tech

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

f(4)

internally it will call apply function of the trait

f.apply(4)

and when we make…

View original post 161 more words