I have encountered a strange bug in Netbeans 8.2.
When declaring an object with a lambda expression, autocomplete for variables inside the lambda does not seem to work, and instead I see global variables, suggestions for keywords amongst other things as shown in the screenshot.
As you can see,
testString
and testString2
are nowhere in sight.
I have tried other objects and the result is always the same.
Now if we do the same with an anonymous inner class, we can see that our variables testString
and testString2
do appear.
Here is the sample code for you to try on your IDEs. I have also included an ActionListener
to demonstrate that the problem doesn't lie with just one interface.
public class SOInner {
private ActionListener listenerExampleLambda = e -> {
//autocomplete DOES NOT work for these vars
int testVarInner = 2;
int testVarInner2 = 4;
};
private ActionListener listenerExampleClass = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//autocomplete works for these vars
int testVarInner = 2;
int testVarInner2 = 4;
}
};
private Comparable<SOInner> comparableExampleLambda = o -> {
//autocomplete DOES NOT work for these vars
String testString = "Hello";
String testString2 = "Hi";
return 0;
};
private Comparable<SOInner> comparableExampleClass = new Comparable<SOInner>() {
@Override
public int compareTo(SOInner o) {
//autocomplete works for these vars
String testString = "Hello";
String testString2 = "Hi";
return 0;
}
};
}
Is there a solution for this bug or has it been recorded already?