• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Choosing correct overloaded method (was useless: Didn't understand the answer)

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Please check this.I have to overloaded methods like this..

----------------------------------------------------------------------------
public void method(Integer i){
System.out.println("Integer version");
}
public void method(String s){
System.out.println("String version");
}
----------------------------------------------------------------------------
And i'm invoking method like this:- method(null);

It gives me following error:-

reference to method is ambiguous, both method method(java.lang.String) in test and method method(java.lang.Integer) in test match
----------------------------------------------------------------------------

But , suppose i change methods like this

public void method(Integer i){
System.out.println("Integer version");
}
public void method(Object o){
System.out.println("Object version");
}
----------------------------------------------------------------------------

It compiles and gives output :- "Integer version"

I thought , it will be same compiler - error?Could you please explain , why it is so?
[ December 19, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.xyzws.com/faq.do?cat=faq&article=8
[ December 19, 2006: Message edited by: Aniket Patil ]
 
swapnil dangore
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Aniket for the link......
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic