Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloaded DataTypes

 
Saumya Srivastava
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was going through this question. And came across some doubts. If somebody can tell me that if there are multiple overloaded functions with different Datatypes then what is the trick to identify that which datatype will be selected? and if it has same datatype of primitive as well as wrapper then which one the compiler will choose to execute it?
The below code is from Certpal. I have modified it a bit.



Thanks in advance,
Saumya
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You should remember there is no implicit downcasting in a method call, so if you have a code like this, it will not compile


2. between primitive and wrapper, primitive is chosen. This applies if the primitive is of the same type as the wrapper and if its of a different type (the latter case is called widening over boxing)...
 
Saumya Srivastava
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:1. You should remember there is no implicit downcasting in a method call, so if you have a code like this, it will not compile


Hi Ankit,

Thanks for your response. I got your second point but not the 1st point. What do you mean by saying implicit downcasting. Also, the line of code you highlighted is running.

Thanks,
Saumya
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the code that I gave should give an error that int cannot be automatically converted to short (you had me doubt my knowledge for a moment). You need to type cast the value 10 in the call to method to short for the code to compile...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic