aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading problem 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 "Overloading problem" Watch "Overloading problem" New topic
Author

Overloading problem

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Does anyone know why the method m(float) is ambiguous ?
Why the result is not "char" ?

Thanks in advance!
Jack
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hi Jack, I was able to compile and run the code with JDK 1.4.2, although my IDE NetBeans did underline the call to m(). I guess, it might be an IDE bug because the code looks fine, float is more common than char, char is more specific.
[ October 20, 2003: Message edited by: Vad Fogel ]
Ian Wu
Greenhorn

Joined: Jul 13, 2003
Posts: 9
The code compiles fine and I got char as the result
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi All
I got the same error as Jack did. I am on JDK 1.4.0.
[ October 20, 2003: Message edited by: Anupam Sinha ]
Harwinder Bhatia
Ranch Hand

Joined: Oct 17, 2003
Posts: 150
Here are my results:
I'm getting char as I expected. Now, I'm wondering why some of you guys are getting float. Can somebody explain this please? Btw, I'm on 1.4.2
Thanks
Harwinder
[ October 20, 2003: Message edited by: Harwinder Bhatia ]
[ October 21, 2003: Message edited by: Harwinder Bhatia ]
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
I addressed this in my last Language Fundamentals article in the JDJ newsletter at http://www.sys-con.com/author/?id=2770. There was an unadvertised change in the language in the 1.4.2 release. In pre-1.4.2 release char is not in the "most specific class" so it is ambiguous. However, this is really a mistake in the original JLS. The section in my book explains it in much greater detail but PLEASE PLEASE PLEASE if you are interested in thei subject wait for the 20031021 version that I will be uploading later today because I have completely rewritten that section and fixed a huge mistake in the process.


Download a copy of <a href="http://www.javarules.com" target="_blank" rel="nofollow"><i>"Mastering The Fundamentals of The Java Programming Language"</i></a>
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
You know I really like this example. It is better than the one I am using now in the book, so I am going to switch to it. If you wait until later today you can download this book and see this example thoroughly explained in context. Thanks for the help.
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
Okay I just completed a rushed recompilation of the book for the sake of JavaRanch memebers. If you turn to section 5.8.2 The Declaring Class of Applicable Methods you will find a detailed discussion of why this example does not compile in pre-1.4.2 releases
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
See also http://www.coderanch.com/t/243546/java-programmer-SCJP/certification/overloading-overriding
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Thanks Doug!!!


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading problem