So, I have the following code:
public class Tester {
public static void doAssert(Object foo, Object bar) {
}
public static void doAssert(Object[] foo, Object[] bar) {
}
public static <T> T getValue(String name, Function<String, T> covert) {
return null;
}
public static void main (String[] args) {
doAssert(getValue("", Double::valueOf), null);
}
}
If I compile this with javac v1.8.0_05, this works fine. Under 1.8.0_65, I get the following error (as reported with -Xdiags:verbose
):
Tester.java:32: error: method doAssert in class Tester cannot be applied to given types;
doAssert(null, getValue("", Double::valueOf));
^
required: Object[],Object[]
found: <null>,Double
reason: argument mismatch; inferred type does not conform to upper bound(s)
inferred: Double
upper bound(s): Object[],Object
1 error
This goes away if I explicitly cast the null
argument to Double
, or if I remove the Object[]
overload of doAssert
.
So...is this a regression in 1.8.0_65 or one of the other intervening releases, or was 1.8.0_05 overly permissive? And why can't javac figure out what it's supposed to do?
(re: the close vote - to me, it's non-obvious how the other Q&A is a duplicate; the linked questions don't appear to deal with method overloading issues, which is required to reproduce this issue.)