Hi, I am preparing for my SCJP exam and when I was looking through JavaRanch's previously posted questions, the following problem occured to me. Consider the following code.
The above program compiles and runs fine. But due to the widening conversions, both the methods are valid. In such a case, I would have expected the first occuring method in the program to be called. However, the compiler seems to be kind of smart and calls the method that has the closest widening conversion. I verified this with another function with signature
and it picked that method. Can anyone explain the reasoning behind this?
So what do we reckon is the reasoning? The spec seems to deal with reference types rather than primitives and conversions. I would have thought that rather than allow a possible loss of information in the least significant digits of the long in the conversion to float the compiler would have chosen the first method ie. output : DDD Cheers -McFly
subject: Passing primitive values to methods and method overloading