Keep getting this error when compiling using Maven:
type parameters of X cannot be determined; no unique maximal instance exists for type variable X wit
This issue can occur when your code is generic and it calls another method that has a generic return type. Sometimes the compiler gets confused trying to figure out how to resolve the method call / return type.
It can be resolved by adding an explicit cast to your code.
// Old code:
public T getValue() {
return otherMethod(); // otherMethod has the signature: <RT> RT otherMethod() { ... }
}
// New code:
@SuppressWarnings("unchecked")
public T getValue() {
return (T) otherMethod(); // the cast tells the compiler what to do.
}
A few things to look at:
It definitely has to do something with the JDK versions maven and eclipse are using. Also make sure your Compiler compliance level in eclipse points to the right JDK version.
I met the same error,use ant. Because when compile by ant or maven,javac use JDK to compile.But in eclipse,it has JDT,that can compile success.
I add below script in my build.xml file:
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
Then,ant can build success.
I am not familiar with Maven. Maybe,it can set the compiler?
In my source code,there are many code like this:
public <X> X find(String hql, Object... values)
{
return (X) HibernateUtils.createQuery(getSession(), hql, values).uniqueResult();
}
Maybe your code too.
But,use JDT,the success is't the final success,in ant.
build.xml can build success only in eclipse.
when I run ant from windows command,fail. Throw another error:
Class not found: org.eclipse.jdt.core.JDTCompilerAdapter
PS, I have copy jar files about JDT in eclipse plugin to ant_home/lib directory.
Wish a little help to you.And our problem can solve.