Community
Participate
Working Groups
Lambda bodies can refer to 'this' of an enclosing scope. Such references to 'this' can lead to inadvertent leaks of the outer object. Anonymous and other inner classes always keep a reference to the outer object, but lambda expressions only do that if necessary (current spec is not clear about this, but beta implementations agree). The Java editor should allow the user to quickly determine whether a lambda expression makes use of 'this' or not. A compile warning/error is not the right device, since references to 'this' are perfectly OK -- they should just be visible. Possible solution: Semantic highlighting. We already render 'static' invocations italic by default, so we could also render a 'static' lambda expression italic. Problem is that an italic '->' is barely distinguishable from an upright '->'. Also rendering '()' and '{}'/';' italic could help a bit. We can't apply the style to the whole lambda, since that would override too many other styles (same dilemma as for boxing/unboxing). Maybe we could show a hover on the '->' that tells whether the lambda binds 'this' or not. The hover could also list the referenced final and effectively final local variables.
(In reply to comment #0) > We can't apply the > style to the whole lambda, since that would override too many other styles (same > dilemma as for boxing/unboxing). Well, you could add CSS classes like class='static-lambda lambda' or class='nested-lambda lambda' to the whole expression and then query the CSS Engine for how to style each sub-part and its combination of CSS classes. The CSS engine could then make everything having 'nested-lambda' underlined, for example. Well, you could if you had this technology. It seems that what's going to happen instead is that the CSS Engine will be relying on you and your preference store keys for its "CSS classes" it will be styling, so to get the behavior from the afore-mentioned example you'd have to create "nested-lambda"-versions of all of your preference store keys and provide them with values, and somehow surface this in the UI. See bug 422536 for a patch in progress.