Bug 458329 - [1.8][quick assist] Allow for converting an anonymous class into a method reference, if possible
Summary: [1.8][quick assist] Allow for converting an anonymous class into a method ref...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 449106
  Show dependency tree
 
Reported: 2015-01-24 07:18 EST by Lukas Eder CLA
Modified: 2020-05-18 09:19 EDT (History)
2 users (show)

See Also:


Attachments
screenshot.png (23.43 KB, image/png)
2020-05-18 09:19 EDT, Lukas Eder CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Eder CLA 2015-01-24 07:18:34 EST
Some anonymous classes can be represented by method references, e.g. as in this example:

--------------------------------------------------------
import java.util.function.Consumer;

public class Test {

    public static void main(String[] args) {
        run(new Consumer<Object>() {
            @Override
            public void accept(Object o) {
                System.out.println(o);
            }
        });
    }

    static void run(Consumer<Object> r) {
        r.accept("Hello");
    }
}
--------------------------------------------------------

The following code is equivalent:

--------------------------------------------------------
    public static void main(String[] args) {
        run(System.out::println);
    }
--------------------------------------------------------

Today, I can convert the anonymous class into a lambda, and then into a method reference. It would be nice to have an option in content assist to go directly from anonymous class to method reference.
Comment 1 Noopur Gupta CLA 2015-01-28 04:37:44 EST
(In reply to Lukas Eder from comment #0)
> Today, I can convert the anonymous class into a lambda, and then into a
> method reference. It would be nice to have an option in content assist to go
> directly from anonymous class to method reference.
You mean:
in *content assist* => in *quick assist*
Comment 2 Lukas Eder CLA 2015-01-28 04:56:21 EST
> You mean:
> in *content assist* => in *quick assist*

Yes, I'm sorry for the confusion. I mean in *quick assist*, i.e. when hitting Ctrl+1
Comment 3 Lars Vogel CLA 2020-05-18 08:04:54 EDT
I think this one is fixed? Lukas, can you check?
Comment 4 Lukas Eder CLA 2020-05-18 09:18:32 EDT
Not fixed in Version 2020-03 / Build id 20200313-1211 yet, see screenshot
Comment 5 Lukas Eder CLA 2020-05-18 09:19:10 EDT
Created attachment 282909 [details]
screenshot.png