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 "=>"))
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 "=>"))
Copyright © 2021 Jogjafile Inc.
def fun( t: Int => Int):Unitis a method that takes a single argument,t. Its type,Int => Int, is a function that takes anInt, and returns anInt. However, the return type offunisUnit.def fun(t: =>Int):Unitis a method that accepts a call by name argumentt. Again, this method's return type isUnit.See What is "Call By Name"? too.
There's no difference between the second and third methods.