On 4/18/2018 11:16 AM, Kevin Bourrillion wrote:
Evaluation of an expression can produce side effects, because expressions may contain embedded assignments, increment operators, decrement operators, and method invocations. *In addition, lambda expressions and switch expressions have bodies that may contain arbitrary statements.A lambda "contains" statements /physically/, but nothing gets executed. If anything, it is anonymous /classes/ that belong here (though maybe, arguably, that would be covered if "method invocations" was changed to "method or constructor invocations"?).
The goal was to highlight that a lambda/switch expression is not like (say) a field access expression, because of the ability to have a body of statements rather than merely a tree of subexpressions ... but you're right, "Evaluation of a lambda expression is distinct from execution of the lambda body." (JLS 15.27.4)
Suggestion: "... because expressions may contain embedded assignments, increment operators, decrement operators, and method or constructor invocations, as well as arbitrary statements nested inside a switch expression."
Yes, limiting the arbitrariness to switch expressions (the sole "home" for something-resembling-block-expressions) is right.
Alex
