val flag = false
if (val data = flag) {
println(data)
}
Is it possible to assign the flag inside a if statement and get evaluated automatically in Scala?
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.
Yes but it doesn’t escape the scope so you cannot use it in body of the if
The assignment doesn’t return a value but you can return it instead. Better to do something like