Jea*_*tin 9 java eclipse jdk1.6 maven
当我尝试执行"mvn install"时,我有这个函数抛出奇怪的错误
public <T> T get(final AN_ENUM key)
{
return some_map.get(key);
}
Run Code Online (Sandbox Code Playgroud)
这是我收到错误的行
final int value = get(AN_ENUM.A_FIELD);
Run Code Online (Sandbox Code Playgroud)
这是maven中的错误:
XXX.java:[25,41] type parameters of <T>T cannot be determined;
no unique maximal instance exists for type variable T with
upper bounds int,java.lang.Object
Run Code Online (Sandbox Code Playgroud)
我已经知道如何"修复它".我只需要在上一个代码示例中更改int
to Integer
,然后bug就会消失.它告诉我maven,由于某种原因,当我使用类型参数时,无法将Integer强制转换为int.
我的问题是......为什么?
在eclipse中,使用相同的JDK,我已经能够运行我的应用程序,没有任何麻烦或警告.
小智 11
我有一个类似的问题,事实证明我试图返回一个"布尔"(原始)而不是"布尔"(对象).由于您尝试将其设置为"int"(原始),因此最终会失败.
尝试将"int"更改为"Integer",希望能解决这个问题.
在您的 中pom.xml
,将目标版本至少设置为 1.5:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这样,Maven 将使用 JDK 1.5(或者如果需要,也可以将其设置为 1.6)。