scala - Pass function argument as code block -
i new scala. have been searching there no easy "search string" seemingly easy question have.
def foo( f: (string) => string ){println(f("123"))} foo{_+"abc"} //works def bar( f :() => string ){println(f())} bar{"xyz"} // why not work? def baz( f: => string ){println(f)} baz{"xyz"} //works
why second (bar
) not work?
second baz
works because it's not function literal, call-by-name parameter. delaying moment of argument computation until it's needed in program. can read in this question. bar
need pass function bar{() => "xyz"}
Comments
Post a Comment