[Java Spec Report] overloading of varargs

Remi Forax <[email protected]> Thu, 29 Jul 2004 11:29:13 +0200
Newsgroups gmane.comp.java.spec-report
Message-ID <[email protected]>
I prepare a course on java, so i made some tests and,
i have a case a little bit strange :

class A {
  void m(int... a) {}
  void m(double... b) {}

  void g(Object... o) {}
  void g(String... s) {}
}

new A().m(3) raise an ambiguity and
new A().g(new Object()) don't.

Using the JLS 3, section 15.12.2.4 says the two m are applicables
and section 15.12.2.5 describe th most specific method
using subtyping relationship.
So because int[] and double[] have no subtyping
relationship, a call to m with an int is ambiguous.

I thing in case of varargs, it seems to me more logic if methods
are compared using the component type of the array and not
the array itself (here double vs int and not double[] vs int[])

Rémi Forax




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/5cFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe from this mailing list, send an email to:
[email protected]
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/java-spec-report/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/