| Summary: | [1.8][clean up] Lambdification produces code that does not compile (Lambda expression's parameter z cannot redeclare another local variable defined in an enclosing scope) | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Steve Northover <steve_northover> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | manju656, stephan.herrmann |
| Version: | 4.4 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
Moving to JDT/UI *** This bug has been marked as a duplicate of bug 424223 *** |
When lambdified, junk() produces the code found in junkBAD() that does not compile. The issue is the variable "z" that is both a local and a parameter to the lambda. Even though you might expect it to shadow (like parameters shadow fields), it does not in the JDK. It might be nice for the parameter to be renamed or Eclipse to refuse to lambdify the expression, but it should not produce code that does not compile. package junk; public class Junk8 { interface Z { int fred(int z); } private static void junk() { int z = 12; Z z2 = new Z() { public int fred (int z) { return z + 1; } }; z2.fred(z); } //BAD LAMBDIFICATION - creates a compile error over "z" private static void junkBAD() { int z = 12; Z z2 = z -> z + 1; z2.fred(z); } }