Community
Participate
Working Groups
Version: 2018-09 (4.9) Build id: I20180906-0745 Test code: -------- package test; import java.util.Map; public class Test { public interface MyInterface {} public enum ClassA implements MyInterface {} public enum ClassB implements MyInterface {} public enum ClassC implements MyInterface {} public enum ClassD implements MyInterface {} static Map<String, Class<? extends MyInterface>> ENUM_FIELDS = of( "a", ClassA.class, "b", ClassB.class, "c", ClassC.class, "d", ClassD.class); public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { return null; } } -------- Compile error: The method of(K, V, K, V, K, V, K, V) in the type Test is not applicable for the arguments (String, Class<Test.ClassA>, String, Class<Test.ClassB>, String, Class<Test.ClassC>, String, Class<Test.ClassD>) If I change the "enum" to "class" the compile error goes away. Also, switching back to Eclipse 4.7.3 does not result in this error.
Also happens in: Eclipse IDE for Eclipse Committers Version: 2018-09 (4.9.0) Build id: 20180917-1800
Thanks, this used to be accepted by ecj all versions prior to 4.9M2. More precisely: it's broken since the fix for bug 537089. Inference seems to fail to infer V to a common super type of Class<ClassA>, Class<ClassB> ... I guess previously, we "accidentally" inferred a wildcard, need to check if that is legal and can be restored for this situation.
Stephan, a college (who discovered this originally) also discovered that this depends on the number of arguments of the "of" method. Two seems to work fine. ---- package test; import java.util.Map; public class Test { public interface MyInterface {} public enum ClassA implements MyInterface {} public enum ClassB implements MyInterface {} public enum ClassC implements MyInterface {} static Map<String, Class<? extends MyInterface>> ENUM_FIELDS_WORKING = of( "a", ClassA.class, "b", ClassB.class); static Map<String, Class<? extends MyInterface>> ENUM_FIELDS_FAILURE = of( "a", ClassA.class, "b", ClassB.class, "c", ClassC.class); public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2) { return null; } public static <K, V> Map<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { return null; } } ----
(In reply to Gunnar Wagenknecht from comment #3) > Stephan, a college (who discovered this originally) also discovered that > this depends on the number of arguments of the "of" method. Two seems to > work fine. Thanks. This is plausible, intersections types become more challenging when more than 2 constituents are involved.
Works again since 4.10. *** This bug has been marked as a duplicate of bug 539329 ***