简体   繁体   English

Eclipse使用泛型编译错误,但使用Maven / javac可以

[英]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: 我的Eclipse IDE(基于Eclipse Luna SR1 4.4.2的Spring Tool Suite版本3.6.4.RELEASE)给我这个Mockito代码一个错误:

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) 类型SearcherClient中的方法findDocumentsByCriteria(GenericCriteria,ParameterizedTypeReference)不适用于自变量(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. 让我感到困惑的是,当我从eclipe(使用Oracle JDK 1.8.0_73)运行maven构建时,它成功完成了。 Other colleagues using same Eclipse STS version, but different OS, doesn't have the compile error. 使用相同Eclipse STS版本但使用不同OS的其他同事没有编译错误。 My OS is Ubuntu 15.04. 我的操作系统是Ubuntu 15.04。

Eclipse uses its own Java compiler (regardless of how you configure it) which sometimes shows incompatibilities with javac. Eclipse使用自己的Java编译器(无论您如何配置),有时都显示与javac不兼容。 Both eclipse compiler and javac compiler have some bugs which are being constantly fixed. eclipse编译器和javac编译器都存在一些错误,这些错误正在不断修复。 Consider updating to the latest Eclipse Mars.2. 考虑更新到最新的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: 我有一个与此类似的问题,maven编译很好,但是Eclipse本身显示出某种错误,您必须在项目属性下检查2个地方:

  1. build path 建立路径

  2. java compiler Java编译器

If you've set correctly only one of these - it won't work. 如果您正确设置了其中一项,则将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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