Functions without arguments, with unit as argument in scala
- by scout
def foo(x:Int, f:Unit=>Int) = println(f())
foo(2, {Unit => 3+4}
//case1
def loop:Int = 7
foo(2, loop) //does not compile
changing loop to
//case 2
def loop():Int = 7
foo(2, loop) // does not compile
changing loop to
//case 3
def loop(x:Unit): Int = 7 //changing according to Don's Comments
foo(2,loop) // compiles and works fine
…