switch from "lambda expression" to "method reference" [message #1758833] |
Mon, 03 April 2017 11:13  |
Eclipse User |
|
|
|
Hello, context assist now always proposes to switch from "lambda expression" to "method reference" when it's possibile, but I think it's wrong because not all conversions are the same thing.
When working with non-final class variables, it shouldn't propose to switch to "method reference".
Below a snippet that produces different results:
public class TestClass {
static class TestClassInt {
int value;
public TestClassInt(int i) {
value = i;
}
public void printMe() {
System.out.println(String.valueOf(value));
}
}
TestClassInt var1;
Runnable r1;
Runnable r2;
public TestClass() {
var1 = new TestClassInt(1);
r1 = () -> var1.printMe();
r2 = var1::printMe;
var1 = new TestClassInt(2);
}
private void print() {
r1.run();
r2.run();
}
public static void main(String[] args) {
new TestClass().print();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.08841 seconds