Community
Participate
Working Groups
3.3 M5 - Example taken from bug 174265: ------- Try.java ----------- package org.example; import java.util.Collections; import java.util.Map; public class Try { void caller() { Map<String, String> emptyMap = Collections.emptyMap(); method(emptyMap); } void method(Map<String, String> map) { } } ------------------------------ - inline "emptyMap" > expected: the resulting code should compile and apparently needs explicit parameterization: method(Collections.<String,String>emptyMap()); < actual: the emptyMap() call is inlined as is, resulting in a compile error.
hey tom! :-)
Darn! Nasty difference between assignment expression and method invocation parameter assignment, see JLS3 15.12.2.8: "If the method result occurs in a context where it will be subject to assignment conversion (ยง5.2) [... then add constraints based on the type of the assignee]". The situation is hard to distinguish from e.g. method(Collections.synchronizedMap(emptyMap)) , since the compiler does the additional inference automatically and only returns the fully resolved binding. Filed API request for compiler (bug 174436).
We should also have a quick fix for turning method(Collections.emptyMap()); into method(Collections.<String,String>emptyMap()); The quick fix will also have to do some guesswork for wildcards: E.g. with void method(Map<String, ?> map) { } , the fix should be: method(Collections.<String, Object>emptyMap());
Fixed in HEAD. See bug 176734 for comment 3.