Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single call-by-name constructor arg not required?

Tags:

scala

Why does line #2 below compile? It's (seemingly) not giving the required constructor arg.

class F(x: => Unit) {}
new F                     // Compiles (strange)
def f(x: =>Unit) = ()
f                         // Does not compile (good)

Is it permitted sugar just for this special case? Can you point to docs on the subject? I'm using Scala 2.9.0.

like image 356
Brian Harris Avatar asked May 23 '11 12:05

Brian Harris


1 Answers

Scala Reference:

5.1.1 Constructor Invocations

If no explicit arguments are given, an empty list () is implicitly supplied.

,where () stands for Unit

like image 81
Vasil Remeniuk Avatar answered Sep 30 '22 09:09

Vasil Remeniuk