-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
8u60, 9
The following produces 3 raw type warnings (with -Xlint), one for each method reference:
import java.util.stream.Stream;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
public class RawMethodRef {
void test1(Stream<? extends Class<String>> stream) {
stream.filter(Class::isInterface);
}
void test2(Stream<String> stream, Function<String, ? extends Optional<String>> f) {
stream.map(f).filter(Optional::isPresent);
}
void test3(Stream<? extends Supplier<String>> stream) {
stream.map(Supplier::get).filter(s -> s.isEmpty());
}
}
There should be no warning, because the type argument in each case is inferred. (test3 demonstrates that, in fact, the type argument is correctly inferred and becomes the type of 's'.)
The warning goes away if I remove the wildcards, so the problem is in the handling of capture variables.
JDK-8039214 had the side-effect of introducing the warning in test2 -- prior to that (e.g., in JDK 8), only test1 and test3 produce warnings.
import java.util.stream.Stream;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
public class RawMethodRef {
void test1(Stream<? extends Class<String>> stream) {
stream.filter(Class::isInterface);
}
void test2(Stream<String> stream, Function<String, ? extends Optional<String>> f) {
stream.map(f).filter(Optional::isPresent);
}
void test3(Stream<? extends Supplier<String>> stream) {
stream.map(Supplier::get).filter(s -> s.isEmpty());
}
}
There should be no warning, because the type argument in each case is inferred. (test3 demonstrates that, in fact, the type argument is correctly inferred and becomes the type of 's'.)
The warning goes away if I remove the wildcards, so the problem is in the handling of capture variables.
- relates to
-
JDK-8039214 Inference should not map capture variables to their upper bounds
- Closed