java – 错误:在Maven安装期间无法确定T的类型参数

前端之家收集整理的这篇文章主要介绍了java – 错误:在Maven安装期间无法确定T的类型参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个功能抛出奇怪的错误,当我尝试做一个“mvn安装”
public <T> T get(final AN_ENUM key)
{
    return some_map.get(key);
}

这是我得到错误的行

final int value = get(AN_ENUM.A_FIELD);

这是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

我已经知道如何“修复”了.我只需要在最后一个代码示例中将int更改为Integer,并且错误消失.它告诉我,maven,由于某种原因,当我使用类型参数时,不能将整数作为int.

我的问题是…为什么?

在日食中,使用相同的JDK,我已经能够运行我的应用程序没有任何种类的麻烦或警告.

> JDK 1.6
Eclipse Indigo服务版本2
> Maven 3.0.4

解决方法

在您的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>

这样,Maven将使用JDK 1.5(如果需要,您可以将其设置为1.6).

原文链接:https://www.f2er.com/java/123693.html

猜你在找的Java相关文章