1

I was reading the definition of getOrElse in Option object:

def getOrElse[B >: A](default: => B): B

Why putting the arrow and not just writing?:

def getOrElse[B >: A](default: B): B

First I thougth that it was like saying "it receives a function that maps Unit to B" but I created a REPL session and it looks it doesn't means that.

scala> def f1(x: => Int) = x
f1: (x: => Int)Int

scala> f1(1)
res6: Int = 1

scala> def f1(x: Int) = x
f1: (x: Int)Int

scala> f1(1)
res8: Int = 1

scala> def f1(x: Unit => Int) = x
f1: (x: Unit => Int)Unit => Int

scala> f1(1)
<console>:10: error: type mismatch;
 found   : Int(1)
 required: Unit => Int
              f1(1)
                 ^
4

0 回答 0