All, after starting at the screen, I had a "Eureka!" moment. I thought that as we're using an int literal 2 (and not explicitly 2l), I thought this was getting resolved at compile time. I applied a variation by creating a new long var, c, and assigning to it the value of b1 and calling the m method with c but that didn't work. i.e
Then I applied a long literal and tried it again but that didn't work as well.
I'm as flummoxed as all of you.
Well, I"m a little less flummoxed now:
JLS Conversions states that a long to float or double conversion is a widening conversion.
Hm, I understand what that means but not why it means what it means.
Given the above, it's possible that a long is implicitly promoted to a float rather than a double.
Check this out:
Take a guess: do you think the above would compile? Run without exceptions?
It does both! No "loss of precision" compiler complaint! JVM happily ran it and printed out:
x is 2 and y is 2.0
Hence, ladies and gentlemen, long to float is considered "widening" and accepted by the compiler AND the JVM. The default conversion would promote a long to a float rather than a double. If you want double, ask for it! Do it explicitly.
Further digging necessary?
[ December 15, 2005: Message edited by: Sasikanth Malladi ]
[ December 15, 2005: Message edited by: Sasikanth Malladi ]