See spec bug JDK-8029640. An unchecked warning should occur if it is necessary to demonstrate the compatibility of the arguments or return type of a method reference.
Example:
import java.util.function.Function;
public class UncheckedInvoke {
Iterable<String> m1(Iterable<String> arg) { return arg; }
Iterable m2(Iterable arg) { return arg; }
void test(Iterable i) {
Iterable i1 = m1(i); // expected: warning; actual: 2 warnings
Iterable<String> i2 = m2(i); // expected: warning; actual: warning
Function<Iterable, Iterable> f1 = this::m1; // expected: warning; actual: warning
Function<Iterable, Iterable<String>> f2 = this::m2; // expected: warning; actual: warning
}
}
I'm not entirely certain why there are two warnings for the invocation of m1 (perhaps to account for the special case in which, per 5.1.9, no unchecked warning occurs, but the signature is still erased?), but the behavior should probably be the same for the reference to m1.
Example:
import java.util.function.Function;
public class UncheckedInvoke {
Iterable<String> m1(Iterable<String> arg) { return arg; }
Iterable m2(Iterable arg) { return arg; }
void test(Iterable i) {
Iterable i1 = m1(i); // expected: warning; actual: 2 warnings
Iterable<String> i2 = m2(i); // expected: warning; actual: warning
Function<Iterable, Iterable> f1 = this::m1; // expected: warning; actual: warning
Function<Iterable, Iterable<String>> f2 = this::m2; // expected: warning; actual: warning
}
}
I'm not entirely certain why there are two warnings for the invocation of m1 (perhaps to account for the special case in which, per 5.1.9, no unchecked warning occurs, but the signature is still erased?), but the behavior should probably be the same for the reference to m1.
- relates to
-
JDK-8029640 Lambda Spec: Require unchecked warnings for parameter/return types of method ref
-
- Closed
-