简体   繁体   中英

Eclipse compile error with generics, but ok with maven/javac

My Eclipse IDE (Spring Tool Suite version 3.6.4.RELEASE based on Eclipse Luna SR1 4.4.2) is giving me an error with this Mockito code:

when(searcherClient.findDocumentsByCriteria(
    any(GenericCriteria.class),
    any(ParameterizedTypeReference.class)))
.thenReturn(
    DataFixture.getGenericDocumentResponse());

The error is:

The method findDocumentsByCriteria(GenericCriteria, ParameterizedTypeReference) in the type SearcherClient is not applicable for the arguments (GenericCriteria, ParameterizedTypeReference)

The signature of the method is this:

public <T> T findDocumentsByCriteria(
    GenericCriteria criteria, 
    ParameterizedTypeReference<T> responseType)

What puzzle me is that when I run a maven build from eclipe (with Oracle JDK 1.8.0_73) it finish with success. Other colleagues using same Eclipse STS version, but different OS, doesn't have the compile error. My OS is Ubuntu 15.04.

Eclipse uses its own Java compiler (regardless of how you configure it) which sometimes shows incompatibilities with javac. Both eclipse compiler and javac compiler have some bugs which are being constantly fixed. Consider updating to the latest Eclipse Mars.2.

I've have a similar issue to this, maven compiling fine, but Eclipse itself showing some kind of error, there are 2 places you have to check under project properties:

  1. build path

  2. java compiler

If you've set correctly only one of these - it won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM