What does Predef.locally do, and how is it different from Predef.identity

It is discussed here: http://www.scala-lang.org/node/3594

The idea was to avoid the programmer error of confusing a ‘dangling’ local block with the template of an object/class/trait.

object test {
  object a
  {
    val x = 1
  }

  object b

  { // oops, extra newline disassociates this block with the object b
    val x = 1
  }
}
test.a.x
//test.b.x // doesn't compile

If the programmer really wants that block to stand alone, locally could be used:

object test {
  object a
  {
    val x = 1
  }

  object b

  locally {
    val x = 1
  }
}

This thread also suggested that the first code would produce a deprecation warning. This has not yet been added.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)