Community
Participate
Working Groups
HEAD ICodeAssist#codeSelect does not resolve correct key for implicit method type arguments. It should return methods with equal keys on the two emptyList() invocations: import java.util.Collections; import java.util.List; public class Try { List<String> get(boolean b) { if (b) return Collections.<String>emptyList(); else return Collections.emptyList(); } } Currently, the first invocation correctly resolves to: Ljava/util/Collections;.emptyList<T:Ljava/lang/Object;>()Ljava/util/List<TT;>;%<Ljava/lang/String;> , whereas the second resolves to: Ljava/util/Collections;.emptyList<T:Ljava/lang/Object;>()Ljava/util/List<TT;>;%<Ljava/lang/Object;> ...........................................................................................^diff^. The difference can also be seen in the Javadoc hover, where the first one has the correct header <String> List<String> java.util.Collections.emptyList() but the second one is <Object> List<Object> java.util.Collections.emptyList().
The SelectionEngine is loosing the return statement: import java.util.Collections; import java.util.List; public class Try { public Try() { } List<String> get(boolean b) { <SelectOnMessageSend:Collections.emptyList()>; } } Thus the inference cannot find out that List<String> should be return. David, please have a look.
Inference from expected type (15.12.2.8) is also meant to work with: - field initialization expression - local variable initialization expression - array initialization
e.g. for array initializer: public class X { String[] strings = { foo() }; static <T> T foo() { return null; } }
Created attachment 108177 [details] Proposed fix
Released for 3.5M1. Tests added GenericsSelectionTest#test0023() ResolveTests_1_5#test0119() -> test0122()
Verified for 3.5M1 using I20080805-1307