File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Choosing correct overloaded method (was useless: Didn't understand the answer) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Choosing correct overloaded method (was useless: Didn Watch "Choosing correct overloaded method (was useless: Didn New topic
Author

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

swapnil dangore
Ranch Hand

Joined: Jun 05, 2006
Posts: 46
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 ]

Cheers<br />-------------<br />Swapnil<br /> <br />SCJP5-81%<br /> <br />"Dictionary is the only place where Success come before Work"
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
http://www.xyzws.com/faq.do?cat=faq&article=8
[ December 19, 2006: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
swapnil dangore
Ranch Hand

Joined: Jun 05, 2006
Posts: 46
Thanks Aniket for the link......
 
jQuery in Action, 2nd edition
 
subject: Choosing correct overloaded method (was useless: Didn't understand the answer)
 
Similar Threads
Question regarding passing null into method parameter
Method Overloading
Method Overloading
Strings
Ambiguous references calling overloaded methods