Method argument inference?

Neal Gafter neal at
Sun Sep 20 08:50:18 PDT 2009


This was considered at one time for Java 7, but it's no longer on the list.
Perhaps for some later revision.  My main concern regarding this change is
that choices made for the changes that are slated for Java 7 might conflict
with this change and therefore make it more difficult to do in the future.
It doesn't appear that the folks working on Java 7 are thinking about that.


On Sun, Sep 20, 2009 at 2:00 AM, John Hendrikx <hjohn at> wrote:

> I'm wondering if there's anything upcoming for Java 7 that's gonna fix
> this problem:
>  dealWithStringSet(Collections.emptySet());
> Where the method is defined as:
>  public void dealWithStringSet(Set<String> strings);
> This gets flagged as a warning by the compiler, as it cannot infer the
> type from the method parameters.  The code below is warning free however
> with an unnecessary intermediate assignment:
>  Set<String> emptySet = Collections.emptySet();
>  dealWithStringSet(emptySet);
> The question is, why is it being flagged at all?  Collections.empySet()
> is clearly setup to conform to any generic type you want it to be, and
> there's no danger (that I can tell) in doing the same inference for
> methods as it is not allowed to write two methods anyway with the same
> erasures.
> Even if it is allowed later to write two methods that only differ in
> generic parameters, one could apply the same error as is used for null
> values (where you have to cast null to conform to the intended type).
> It is just a minor annoyance, but one that gets more frequent as more
> and more frameworks and methods adopt generics :)
> --John

More information about the coin-dev mailing list