Scala: Why can I convert Int to Unit?

后端 未结 3 709
无人及你
无人及你 2020-12-06 16:14

I\'ve recently started playing with Scala (2.8) and noticed the I can write the following code (in the Scala Interpreter):

scala> var x : Unit = 10
x : Un         


        
3条回答
  •  悲哀的现实
    2020-12-06 16:54

    See section "6.26.1 Value Conversions" in the Scala Language Specification version 2.8:

    ...

    Value Discarding. If e has some value type and the expected type is Unit, e is converted to the expected type by embedding it in the term { e; () }.

    ...

提交回复
热议问题