1

I wonder, why doesn't this work:

object test {
  def method1(a: Int) = println(a)  // println a -- doesn't work either

  method1 123
}

method1 takes only parameter, that is, it can be possible to omit parenthesis, can't it?

Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
  • This was already answered here: http://stackoverflow.com/questions/1181533/what-are-the-precise-rules-for-when-you-can-omit-parenthesis-dots-braces-f – Eugene Ryzhikov Aug 14 '13 at 17:04

1 Answers1

2

This is a conflict with postfix operation. Let's have a look at your example:

 println a 

The parser would interpret this as

 println.a

It would be very confusing if you could write

 println 123

(which is distinguishable, since 123 is not a valid method name), but now if you replace 123 by a variable holding the value, you'll get something like member a not found on println.

gzm0
  • 14,752
  • 1
  • 36
  • 64