Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading problem

 
Jack Lau
Ranch Hand
Posts: 168
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know why the method m(float) is ambiguous ?
Why the result is not "char" ?

Thanks in advance!
Jack
 
Vad Fogel
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code compiles fine and I got char as the result
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Doug Dunn
Author
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also http://www.coderanch.com/t/243546/java-programmer-SCJP/certification/overloading-overriding
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Doug!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic