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
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;
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;
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💥️