-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
17, 18, 19
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Compiling the provided snippet results in an error. Compilation with `-Xdiags:verbose` succeeds.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java
javac -Xdiags:verbose Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
class files created
ACTUAL -
First command results in an error:
Test.java:13: error: incompatible types: invalid method reference
.forEach(CorridorProperties::toJson);
^
method toJson in class CorridorProperties cannot be applied to given types
required: no arguments
found: Object
reason: actual and formal argument lists differ in length
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
Second command succeeds.
---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.function.Function;
public class Test {
public static class CorridorProperties { public void toJson() {} }
public interface CorridorPropertiesResolver { CorridorProperties resolveFor(Object ctx); }
private void corridorProperties() {
wrap(user -> {
List.<CorridorPropertiesResolver>of().stream()
.map(resolver -> resolver.resolveFor(user))
.forEach(CorridorProperties::toJson);
return null;
});
}
private static Object wrap(Function<String, Void> handler) {
return null;
}
}
---------- END SOURCE ----------
FREQUENCY : always
Compiling the provided snippet results in an error. Compilation with `-Xdiags:verbose` succeeds.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java
javac -Xdiags:verbose Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
class files created
ACTUAL -
First command results in an error:
Test.java:13: error: incompatible types: invalid method reference
.forEach(CorridorProperties::toJson);
^
method toJson in class CorridorProperties cannot be applied to given types
required: no arguments
found: Object
reason: actual and formal argument lists differ in length
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
Second command succeeds.
---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.function.Function;
public class Test {
public static class CorridorProperties { public void toJson() {} }
public interface CorridorPropertiesResolver { CorridorProperties resolveFor(Object ctx); }
private void corridorProperties() {
wrap(user -> {
List.<CorridorPropertiesResolver>of().stream()
.map(resolver -> resolver.resolveFor(user))
.forEach(CorridorProperties::toJson);
return null;
});
}
private static Object wrap(Function<String, Void> handler) {
return null;
}
}
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-8268312 Compilation error with nested generic functional interface
-
- Resolved
-