Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » switch from "lambda expression" to "method reference"
switch from "lambda expression" to "method reference" [message #1758833] Mon, 03 April 2017 15:13 Go to next message
Nicola  Zanaga is currently offline Nicola ZanagaFriend
Messages: 49
Registered: July 2009
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() {

    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() {;;

    public static void main(String[] args) {
        new TestClass().print();


Re: switch from "lambda expression" to "method reference" [message #1760762 is a reply to message #1758833] Tue, 02 May 2017 16:38 Go to previous message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 17
Registered: July 2009
Junior Member
Are you talking about this line of code?

r1 = () -> var1.printMe();

There's no compiler error when this is converted to a method reference. So, I don't see why the conversion can't be offered.
Previous Topic:Is JRE 9 compatibile with Eclipse 3.8 RCP Application?
Next Topic:Dependent Projects and JAR files
Goto Forum:

Current Time: Sat Mar 24 06:38:12 GMT 2018

Powered by FUDForum. Page generated in 0.01842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software