This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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