28
Apr 09

javac bug – no unique maximal instance

While trying to compile my java class files with the 1.6 java compiler, I came across an error message that read :

no unique maximal instance exists for type variable U with upper bounds U

The weird thing was that the file compiled just fine in eclipse!

On further probing I realized it’s a javac bug (check the bug here)

Here’s the workaround -

Bug Scenario :

public class SomeObject {

<U extends SomeObject> U foo1() throws Exception {

SomeObject obj = new SomeObject();
return obj.foo1();
}

}

Solve this way :

public class SomeObject {

<U extends SomeObject> U foo1() throws Exception {

SomeObject obj = new SomeObject();
return obj.<U>foo1();
}
}