Community
Participate
Working Groups
I'm in the process of upgrading from 2021-03 to 2021-09 and believe I have found a regression in JDT's handling of a method reference that points to an overloaded method. Here's some sample code that will hopefully illustrate the problem: package example; class Example { Example() { inspect(this::singleMethod); inspect(this::overloadedMethod); } void inspect(Inspector... inspectors) { } void singleMethod(byte[] input, int offset, int len) { } void overloadedMethod() { } void overloadedMethod(byte[] input, int offset, int len) { } } @FunctionalInterface interface Inspector { void update(byte[] input, int offset, int len); } It compiles without error using 2021-03. With 2021-09 it fails on the line "inspect(this::overloadedMethod);" stating that "The target type of this expression must be a functional interface". I've also tried the I20210920-1800 build of 2021-12 and see the same compilation failure.
See also bug 576174
The regression is between SDK-I20210624-1800 (OK) and SDK-I20210627-1800 (BAD). I will try to find offending commit. Combined example from this and bug 576174: import java.util.function.Supplier; class Example { Example() { inspect(this::singleMethod); inspect(this::overloadedMethod); } void inspect(Inspector... inspectors) { } void singleMethod(byte[] input, int offset, int len) { } void overloadedMethod() { } void overloadedMethod(byte[] input, int offset, int len) { } public static void main(String[] args) { String s1 = hoge1(String::new); String s2 = hoge2(String::new); // Error. See the attached file. } static <T> T hoge1(Supplier<T> sup) { return null; } static <T> T hoge2(Supplier<T>... sup) { return null; } } @FunctionalInterface interface Inspector { void update(byte[] input, int offset, int len); }
*** Bug 576174 has been marked as a duplicate of this bug. ***
(In reply to Andrey Loskutov from comment #2) > The regression is between SDK-I20210624-1800 (OK) and SDK-I20210627-1800 > (BAD). > I will try to find offending commit. This is a regression from bug 573933. Reverting commit http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=67749b18db7e9a1536311a699e298db1d2da7f86 fixes the compilation.
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185699
Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185699 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=feb6cf9983219098bed9b29579472555a5d33123
Verified with I20210926-0600
*** Bug 576437 has been marked as a duplicate of this bug. ***