fork download
  1. object Main {
  2. def main(args: Array[String]) {
  3. functionTakingFunction(TestObj1.testFunction _)
  4. functionTakingFunction(TestObj2.testFunction)
  5. }
  6.  
  7. def functionTakingFunction(callback: () => String) {
  8. println(callback)
  9. println("Call returns: " + callback())
  10. }
  11. }
  12.  
  13. object TestObj1 {
  14. def testFunction = "Some text"
  15. }
  16.  
  17. object TestObj2 {
  18. def testFunction() = "Some text"
  19. }
Success #stdin #stdout 0.37s 382976KB
stdin
http://stackoverflow.com/questions/18338636/why-in-scala-function-defined-without-empty-parentheses-doesnt-behave-like-func
stdout
<function0>
Call returns: Some text
<function0>
Call returns: Some text