相同的源代码,Eclipse构建成功,但Maven(javac)失败 [英] Same source code, Eclipse build success but Maven (javac) fails
问题描述
在使用Maven进行编译时遇到此错误:
Keep getting this error when compiling using Maven:
type parameters of <X>X cannot be determined; no unique maximal instance exists for type variable X with upper bounds int,java.lang.Object
干扰不能应用于原始类型。但是我认为从Java5开始,Boxing / unboxing机制在原始类型和包装类之间无缝地工作。
Generics type interference cannot be applied to primitive types. But I thought since Java5, boxing/unboxing mechanism works seamlessly between primitive types and wrapper classes.
在任何情况下,奇怪的是Eclipse不报告任何错误,愉快地编译。我使用JDK1.6.0_12。
In any case, the strange thing is Eclipse doesn't report any errors and happily compiles. I'm using JDK1.6.0_12. What could possibly be the problem here?
推荐答案
当你的代码是通用的,并且它调用另一个方法,通用返回类型。有时编译器会试图弄清楚如何解决方法调用/返回类型。
This issue can occur when your code is generic and it calls another method that has a generic return type. Sometimes the compiler gets confused trying to figure out how to resolve the method call / return type.
它可以通过添加一个显式转换到您的代码。
It can be resolved by adding an explicit cast to your code.
// Old code:
public T getValue() {
return otherMethod(); // otherMethod has the signature: <RT> RT otherMethod() { ... }
}
// New code:
@SuppressWarnings("unchecked")
public T getValue() {
return (T) otherMethod(); // the cast tells the compiler what to do.
}
这篇关于相同的源代码,Eclipse构建成功,但Maven(javac)失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!