6.4 Working with Variables in Lambdas Flashcards

1
Q

📝️ What are the different variables exists in a Lambda expression?

A
  • > Parameter list variables
  • > Local variables inside the lambda body
  • > External variables referenced from the lambda body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

📝️ What are the lambda’s parameter variables rules?

A

o The parameter type is optional
o You can even use var in place of the specific type
o Single parameter (without type) does NOT require parentheses
🤯️⚠️📣️ When declaring parameter type/var use parentheses

  • > Predicate p = x -> true;
  • > Predicate p = (String x) -> true;
  • > Predicate p = (var x) -> true;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

📝️ What are the lambda’s local variables inside the body rules?

A
  • > You can’t redeclare an existent variable on param-list / external variable referenced
  • > Watch out Missed ‘;’ semi-colon at the end;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

📝️ What are the lambda’s external variable rules?

A
  • > Class/Instance variables are always allowed.

- > Method parameters and local variables are allowed to be referenced if they are 💥️effectively final💥️

How well did you know this?
1
Not at all
2
3
4
5
Perfectly