0

Scala code:

{ "abc" }

What the type of it? Is it => String, or just String?

Freewind
  • 193,756
  • 157
  • 432
  • 708

2 Answers2

3

Maybe it's worth saying that the type of the block is the type of its result expression.

http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#blocks

More or less.

The expected type of the final expression e is the expected type of the block.

That's the case (obviously) for f { "abc" }. You get conversions based on the param type to the function.

som-snytt
  • 39,429
  • 2
  • 47
  • 129
1

It's a String

scala> { "abc" }
res0: String = abc
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235