• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt in overloading using var args

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


When I compile this code I get error::

E:\Priyam>javac Query2.java
Query2.java:10: reference to show is ambiguous, both method show(int,int...) in
Query2 and method show(int...) in Query2 match
show(1);
^
Query2.java:11: reference to show is ambiguous, both method show(int,int...) in
Query2 and method show(int...) in Query2 match
show(1,2);
^
2 errors

My question is when I call the show method using show(1), why doesn't the complier matches it with show(int... y)???
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priyam,
It also matches and satisfies for show(int x,int... y),Compiler can't determine which one to select.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, ranchers,

the methods themself however do compile.
As there is one possibility to call the method without being ambigous:

show();


Yours,
Bu.
 
"To do good, you actually have to do something." -- Yvon Chouinard
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic