Community
Participate
Working Groups
Hello, When using a generic factory method like: public static <T, U extends T> TypedCollection<T> createTypedCollection(Class<U> c) to do something along the lines of: TypedCollection<SuperType> = createTypedCollection(SubType.class) if will compile fine with Eclipse and is completely workable, but will not compile with javac (1.5.0_09). I plan to test this with the nightly build of eclipse once it is done downloading. I have not yet managed to find a spec with who is correct in this case. I have test classes that show this working in eclipse, but returning the error message: incompatible types found : TypedCollection<SubType> required: TypedCollection<SuperType>
Please attach a complete test case for investigation.
Created attachment 53917 [details] Code that compiles in eclipse, but not sun Code is in the default package. javac *.java does not compile, but it does in eclipse.
I believe our behavior is correct; and that it would indicate a bug in javac. Basically acording to JLS 15.12.2.8, the invocation of <T, U extends T> TypedCollection<T> createTypedCollection(Class<U> c) should yield {U == SubTypeClass} and {T == SuperTypeAbstractClass}. U being inferred during argument inference 15.12.2.7, and T being inferred from 15.12.2.8 from expected type (invocation occurs on right hand side of variable declaration). Marking the bug as invalid, since our behavior is correct already. Added GenericTypeTest#test1242
btw, I just checked javac 1.7 (1.7.0-ea), and he seems they now agree with us as well.
Verified for 3.4M5