Skip to content


explain this

type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object

In java 1.6u2 running in maven 2.0.7, we started getting this message but in eclipse 3.3.0 we were not. (and in idea we also were failing)

First, what the hell does this message means? Second, why can eclipse handle the issue and not the regular jdk?

Anyhow the problem was caused by this (our example was a little more complex than this):

public <T> T getFoo() {
T result;
result = getBar();
return result;
}

public <T> T getBar() {
return (T) map.get("bar");
}

The workaround is casting the line:

result = getBar();


to:

result = (T)getBar();

Posted in help notes, technical.


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Clemens Renner says

    Thanks a lot for the post. It saved our day debugging the migration to Maven with a few projects.

    IMHO this is just another hint at how badly generics have been implemented in Java.

  2. Arman Sharif says

    I had a similar problem where I also used casting as a workaround. There’s another side to this problem though related to autoboxing.

    For example, if T is an Integer, the following code will compile in eclipse but fail with javac

    int result = getFoo();

    The error message from javac is “type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object”

    The only way to get the above code building with both is to give up autoboxing completely:

    Integer result = getFoo();

    This was using Eclipse 3.3.1.1 and java 5 (1.5.0_14-b03).

Continuing the Discussion

  1. Generic annoyances in java « Just wondering…. linked to this post on January 6, 2010

    […] This compiles just fine in eclipse, but once again sun’s javac is temperamental. […]

  2. Woot! I crashed the javac « Just wondering…. linked to this post on January 7, 2010

    […] again (and again) the eclipse compiler is more robust than the sun […]



Some HTML is OK

or, reply to this post via trackback.