Home  >  Article  >  Java  >  A little tip about Java generics

A little tip about Java generics

高洛峰
高洛峰Original
2016-11-16 10:12:011722browse

A small tip about Java generics

Use ArgumentCaptor to capture the parameters in the mock method as shown below

ArgumentCaptor> fooCaptor = ArgumentCaptor.forClass(List.class);

Error reporting

Error:(89, 86) java: incompatible types: org.mockito.ArgumentCaptor cannot be converted to org.mockito.ArgumentCaptor>

Solution

Using a higher version of Mockito--mockito-core-2.0.36-beta

Code comparison

mockito-core-1.0.19

public static  ArgumentCaptor forClass(Class clazz) {
    return new ArgumentCaptor(clazz);
}

mockito-core-2.0.36-beta

public static  ArgumentCaptor forClass(Class clazz) {
    return new ArgumentCaptor(clazz);
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn