10

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
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • 2
    What's the source level in the maven compiler plugin in the POM.xml? Is it set to less than 1.5? – GMK Jul 31 '12 at 19:41
  • 2
    What happens if you compile with javac? You might find this is a discrepancy between ECJ and javac. – hertzsprung Jul 31 '12 at 20:07

2 Answers2

11

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.

Gary
  • 111
  • 1
  • 2
3

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).

Benedikt Köppel
  • 4,853
  • 4
  • 32
  • 42