Keep getting this error when compiling using Maven:
type parameters of <X>X cannot be determined; no unique maximal instance exists for type variable X with upper bounds int,java.lang.Object
Generics type interference cannot be applied to primitive types. But I thought since Java5, boxing/unboxing mechanism works seamlessly between primitive types and wrapper classes.
In any case, the strange thing is Eclipse doesn't report any errors and happily compiles. I'm using JDK1.6.0_12. What could possibly be the problem here?
The error message indicates that Maven is unable to find the Java compiler, which comes only with a JDK and not with a JRE.
Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.
java. Update the App class to use Util class. Now open the command console, go the C:\MVN\consumerBanking directory and execute the following mvn command. After Maven build is successful, go to the C:\MVN\consumerBanking\target\classes directory and execute the following java command.
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.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With