Reputation: 369
I am new to Scala. Please tell the difference between
def fun( t: Int => Int):Unit = {
and
def fun(t: =>Int):Unit {
and
def fun(t:=>Int):Unit { (without space b/w ":" and "=>"))
Upvotes: 2
Views: 138
Reputation: 41939
def fun( t: Int => Int):Unit
is a method that takes a single argument, t
. Its type, Int => Int
, is a function that takes an Int
, and returns an Int
. However, the return type of fun
is Unit
.
def fun(t: =>Int):Unit
is a method that accepts a call by name argument t
. Again, this method's return type is Unit
.
See What is "Call By Name"? too.
There's no difference between the second and third methods.
Upvotes: 4