This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading problem

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Can anybody explain the reason of ambiguity here.

 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: char can be automatically upcasted to float...
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


First thing i suppose that var-args are the last choice made by the compiler. In your case, if your see there is already a more specific method
present that is number 1 which takes a float. Now when you try to invoke the method calls from your main method, in your second call, as Ankit
told character is automatically up-casted to float then the compiler gets confused, which method to call as there is already a more specific method
present. Thats why it gives the ambiguity error. Hope this helps.
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean character can be automatically casted to int, float etc
 
Ankit Garg
Sheriff
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sonia wrote:So you mean character can be automatically casted to int, float etc

Yes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic