Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: type parameters of <T>T cannot be determined during Maven Install

I have this function throwing weird error when I try to do a "mvn install"

public <T> T get(final AN_ENUM key)
{
    return some_map.get(key);
}

This is the line where I get the error

final int value = get(AN_ENUM.A_FIELD);

And this is the error in 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

I know already how to "fix it". I just need to change the int to Integer in my last code sample and the bug goes away. It tell me that maven, for some sort of reason is not able to cast an Integer as an int when I use a type parameter.

My Question is.. why ?

In eclipse, using the same JDK, I have been able to run my application without any kind trouble nor warning.

  • JDK 1.6
  • Eclipse Indigo Service Release 2
  • Maven 3.0.4
like image 321
Jean-Christophe Fortin Avatar asked Jul 31 '12 18:07

Jean-Christophe Fortin


2 Answers

I had a similar issue and it turns out that I was attempting to return a "boolean"(Primitive) and not a "Boolean"(Object). Since you're trying to set it to an "int"(primitive) it will end up failing.

Try changing your "int" to an "Integer" and hopefully that should fix it.

like image 131
Gary Avatar answered Sep 28 '22 02:09

Gary


In your pom.xml, set the target version to at least 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>

This way, Maven will use JDK 1.5 (or you can set it to 1.6 if you want).

like image 20
Benedikt Köppel Avatar answered Sep 28 '22 02:09

Benedikt Köppel