Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading problem

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

 
Ankit Garg
Sheriff
Posts: 9509
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: 180
  • 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: 9509
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