-
Bug
-
Resolution: Duplicate
-
P3
-
12, 14, 17, 18
A DESCRIPTION OF THE PROBLEM :
The provided code not compiled, although it seems should.
REGRESSION : Last worked in version 11.0.14
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile provided code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code to be compiled.
ACTUAL -
The compilation error:
error: incompatible types: invalid method reference
.map(URI::create)
^
incompatible types: Object cannot be converted to String
---------- BEGIN SOURCE ----------
package example;
import java.net.URI;
import java.net.http.HttpResponse;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
}
static <T> void test() {
CompletableFuture<HttpResponse<T>> f = CompletableFuture.completedFuture(null);
f.thenApplyAsync(response -> {
Stream.of("Location", "Content-Location")
.flatMap(s -> response.headers().allValues(s).stream())
.map(URI::create)
.collect(Collectors.toList());
return response;
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
To not use lambda expression instead of method reference.
FREQUENCY : always
The provided code not compiled, although it seems should.
REGRESSION : Last worked in version 11.0.14
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile provided code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code to be compiled.
ACTUAL -
The compilation error:
error: incompatible types: invalid method reference
.map(URI::create)
^
incompatible types: Object cannot be converted to String
---------- BEGIN SOURCE ----------
package example;
import java.net.URI;
import java.net.http.HttpResponse;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
}
static <T> void test() {
CompletableFuture<HttpResponse<T>> f = CompletableFuture.completedFuture(null);
f.thenApplyAsync(response -> {
Stream.of("Location", "Content-Location")
.flatMap(s -> response.headers().allValues(s).stream())
.map(URI::create)
.collect(Collectors.toList());
return response;
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
To not use lambda expression instead of method reference.
FREQUENCY : always
- duplicates
-
JDK-8268312 Compilation error with nested generic functional interface
-
- Resolved
-