1

Looking at akka's source I faced the following construction:

def apply[T <: Actor: ClassTag](creator: ⇒ T): Props

I was confused by the creator: ⇒ T parameter declaration. So, trying it myself

class TestFunction {
  def test(foo: => Int) = {
    println(foo.getClass)
    println(foo)
  }
}

val testFoo = TestFunction()
testFoo.test(10)

I got the following result:

int
10

And it works completely the same as if it would be declared just as def test(foo: Int). What does => stand for in the parameter declaration?

stella
  • 2,546
  • 2
  • 18
  • 33
  • 1
    Use http://symbolhound.com/ for weird-looking method names. – dveim Aug 25 '16 at 11:36
  • 2
    Basically, => means "call by name". If you don't include the =>, it defaults to call by value. It would have been hard to realize this question was a duplicate since you didn't know the term "call by name". – John Aug 25 '16 at 14:56

0 Answers0