Is there any difference between the following
def foo(s: String) = { ... }
and
def foo(s: => String) { ... }
both these definitions accept “sss” as parameter.
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.
An argument
Stringis a by-value parameter,=> Stringis a by-name parameter. In the first case, the string is passed in, in the second a so-called thunk which evaluates to aStringwhenever it is used.Often a by-name parameter is not used to evaluate it several times, but to lazily evaluate it once.