0

Scala code:

{ "abc" }

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

Freewind
  • 177,284
  • 143
  • 381
  • 649

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
  • 38,672
  • 2
  • 41
  • 120
1

It's a String

scala> { "abc" }
res0: String = abc
Gabriele Petronella
  • 102,227
  • 20
  • 204
  • 227