0

To my beginner's knowledge of Scala there isn't any way to achieve the last line. I hope I am mistaken, and I just wanted to confirm. Also, I don't understand why, because the compiler should know the owner object of the f method from the import statement.

object A { def f(s: Any) = println(s) }
import A.f
A f 1 //Works
f 2 // Does not compile

For clarification there are two questions:

  1. How should a single parameter method without parenthesis and explicit owner object reference be called? (See the subject.)
  2. What is the reason the compiler cannot understand the last statement?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0
object A { def f(s: Any) {println(s)} }
import A.f
A f 1 //works
f(2) // works

What are the precise rules for when you can omit parenthesis, dots, braces, = (functions), etc.?

Community
  • 1
  • 1