Java 1.8 with Mockito 1.9.5 gives compile errors
java, mockito
Solution
Since java 8, the compiler type inference have been greatly improved.
Now you could remove the class parameter from the matcher without any compilation warning:
when(implClassMock.executeTask(any())).thenReturn(null);
Note: i have the same compiler failure but only with eclipse. A bug may be ?
Problem
After switching to Java 1.8. JDK some of my test classes fail to compile. Example of implementation class: ``` import java.util.concurrent.Callable; import java.util.concurrent.Future; public class ImplClass { public <T> Future<T> executeTask(final Callable<T> task) { return null; } } ``` And here is the test class with Mockito: ``` import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.concurrent.Callable; import org.junit.Before; public class TestClass { private ImplClass implClassMock; @Before public void setUp() { implClassMock = mock(ImplClass.class); when(implClassMock.executeTask(any(Callable.class))).thenReturn(null); } } ``` I get the error message: `The method executeTask(Callable<T>) in the type ImplClass is not applicable for the arguments (Callable)` Switching back to java compiler 1.7 everything is fine. Any idea how to resolve this issue?