The problem is that type inference has been improved. anyVararg() is a generic method, but you use it in a nested method call. Before Java 8, type inference restrictions forced the <T> T anyVararg() method to be <Object> Object anyVararg() when placed as an argument to call another method without inserting explicit type arguments.
Thus, only query(String, ResultSetHandler, Object...) , as the third argument, was considered as an Object type.
But now that Java 8 type output works with nested method calls. Since for <T> T anyVararg() parameter of type <T> can be anything, it can be a ResultSetHandler . Thus, query(String,Object,ResultSetHandler) also a candidate candidate.
(I omitted a parameter of type <T> from an external call in both cases to make it less confusing)
Since we have two possible matches, the usual procedure for selecting a method is used here. And yes, this is ambiguous. The first parameter is the same, String , but for the other two ResultSetHandler more specific than Object , but while one candidate takes on a more specific type for the second parameter, the other makes for the third (and subsequent) window).
Clearly, type parameters that allow you to return a method type as anything are a source of ambiguity, but APIs like Mockitos containing such methods are a cornerstone of Java programming. You will have to force the type to be either the generic Matchers.<Desired>anyVararg() , or using the cast (Desired)anyVararg() .
Holger
source share