What exactly that declaration of method parameter means:
def myFunc(param: => Int) = param
What is meaning of => in upper definition?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is so-called pass-by-name. It means you are passing a function that should return
Intbut is mostly used to implement lazy evaluation of parameters. It is somewhat similar to:Here is an example. Consider an
answerfunction returning someIntvalue:And two functions, one taking
Intand one takingIntby-name:Now execute both of them using
answer:The first case is obvious: before calling
eagerEval()answeris evaluated and prints"answer"string. The second case is much more interesting. We are actually passing a function tolazyEval(). ThelazyEvalfirst prints"lazy"and evaluates thexparameter (actually, callsxfunction passed as a parameter).See also