Community
Participate
Working Groups
The following test code will generate a "Bound Mismatch" error when compiled under 3.1M7: public class Test { public static <V extends ValueObject, P extends Persistent<V>> P createDataObject( V value ) { // create some type of data object given a value object [code ommitted] return (P)null; } public static void testCreateDataObject() { ValueObject v = new AValueObject(); Persistent d = createDataObject( v ); } private interface Persistent<V extends ValueObject> { public V getValueObject(); } private interface ValueObject { } public static class AValueObject implements ValueObject { } public static class ADataObject implements Persistent<AValueObject> { public AValueObject getValueObject() { return new AValueObject(); } } } But when compiled using javac [Sun Java 1.5.03] with -Xlint:all the following warning is issued: Test.java:13: warning: [unchecked] unchecked conversion found : <P>P required: Test.Persistent Persistent d = createDataObject( v ); ^ 1 warning Work-around to this problem is to change the above line to: Persistent<ValueObject> d = createDataObject( v ); but this should not be required since the unchecked base version will assume all implementations of Persistent will extend Persistent<ValueObject>.
Reproduced in 3.1rc1
Reduced testcase: public class X { public static <V, P extends Persistent<V>> P createDataObject(V value) { return null; } public static void testCreateDataObject(Object v) { Persistent d = createDataObject(v); } private interface Persistent<V> { public V getValueObject(); } }
Problem comes from inference using expected return type which did not perform substitution of variable (P) upper bound (Persistent<V> --> Persistent<Object>). Added GenericTypeTest#test710. Also, the unchecked warning from javac looks like a bug. Inference should figure P is Persistent<Object>, and this needs no unchecked warning (guessing it infers raw Persistent instead). Fixed
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
Verified with I20050610-0010