i need some explanation about the conversion from long to float and why convert to double as we know double is A defult and long 64 and float32
Igor Zeta
Ranch Hand
Joined: Nov 12, 2002
Posts: 40
posted
0
Originally posted by tony kanvas:
In this code i see there's a call to an overloaded method,i think it will be called the triple int parameters method because best fits the call, so why the thought of converting? I apologize for my poor english...!
ciao<br />Igor Zeta<br />SCJP1.4
Rehana Shaik
Ranch Hand
Joined: Jan 03, 2003
Posts: 33
posted
0
Conversion rule's in java are as follows byte-->short--> int -->long--> float -->double
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Originally posted by Rehana Shaik: Conversion rule's in java are as follows byte-->short--> int -->long--> float -->double
Anything moving in the diredction of the arrows does not require a cast. Anything moving against the arrows requires a cast.
Anything moving in the diredction of the arrows does not require a cast. Anything moving against the arrows requires a cast.
If the order given above is to be taken into account, how could one explain the result of the above program as Hello World! One instead of Hello World! Two because the middle varibale of the method which prints Two is a double.That would be even more precise...or am I missing something here? Thanks in advance Sri
Rehana Shaik
Ranch Hand
Joined: Jan 03, 2003
Posts: 33
posted
0
Method call conversions always look for the exact data type or a wider one in the method signatures. They will not do narrowing conversions to resolve methods, instead we will get a compile error. so it will go for float other than double.
John Paverd
Ranch Hand
Joined: Nov 17, 2002
Posts: 115
posted
0
From the Java Language Specification, Section 15.12:
The Java programming language uses the rule that the most specific method is chosen. The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.
The method "Two" could not "pass on" the call to the method "One" because it would require an explicit cast of the 2nd parameter from double to float. However, method "One" could "pass on" the call to method "Two", because the compiler can implicitly widen the 2nd parameter from float to a double. Therefore method "One" is more specific than method "Two" and is chosen by the compiler. And it's difficult to see in my browser, but the arguments in the method call are 7L, not 71.
SCJP 1.4
Sridhar Srikanthan
Ranch Hand
Joined: Jan 08, 2003
Posts: 366
posted
0
Oops, John, Even i thought them to be 71 instead of 7L. my mistake Thanks for the answer Sri