Community
Participate
Working Groups
Created attachment 283000 [details] Screenshot of bug When inlining the method 'inlineMe' in the following code: --- 8< --- package inlining.bug; public class Bug { static void inlineMe() { System.out.println("Inline me"); } static Runnable methodReference() { final Runnable runnable = Bug::inlineMe; return runnable; } } --- 8< --- the method reference is just deleted from the code, not in-lined as expected. As a result, the inlining operation results in a compile time error.
Tested this against 4.15, haven't verified if the same bug exists in 4.16
Idea: should we actually disallow inlining methods used in a method reference? Users can still achieve it in two steps: - convert method reference to lambda - inline method Hoping that this works...
I think deletion of inlining should be prevented if there are method references. However, if the method is used elsewhere then perhaps that could be inlined. -- void foo() { System.out.print("foo"); } void bar() { foo(); } Runnable ref() { return this::foo; } -- In this case, it might be OK to in-line the 'foo' call in bar' but while there's still a reference to this::foo, it probably wouldn't be good to delete it. What I was actually hoping for was to replace the this::foo with a lambda, so: -- public class Bug { static void inlineMe() { System.out.println("Inline me"); } static Runnable methodReference() { final Runnable runnable = () -> Bug.inlineMe(); return runnable; } } -- That doesn't work either, because 'inlineMe' needs to be a set of statements, not an expression. However, this works: -- package inlining.bug; public class Bug { static void inlineMe() { System.out.println("Inline me"); } static Runnable methodReference() { final Runnable runnable = () -> { Bug.inlineMe(); }; return runnable; } } --
Created attachment 283001 [details] Inlining with lambda
The point is that while it's possible to allow method references to be inlined, the current behaviour should be to prevent its deletion while there are still method references out there; but preferably, it should be possible to inline a method reference and treat it as if the user had converted it to a lambda as an interim step as per comment 3.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.