Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.340 :

Posted: Fri Jan 24, 2014 5:39 am
by devlam
In the case of i == f, value of i will be promoted to a float i.e. 5.0, and so it returns false.

What is the rule behind this?
Why is f not converted to an int?

Re: About Question com.enthuware.ets.scjp.v6.2.340 :

Posted: Fri Jan 24, 2014 5:53 am
by admin
The rule is explained in Section 15.21.1. "Numerical Equality Operators == and !=", which refers to Section 5.6.2.
"Binary Numeric Promotion" of Java Language Specification. To quote -
Otherwise, if either operand is of type float, the other is converted to float.
You might want to go through the above referred sections for full details. Here is the link http://docs.oracle.com/javase/specs/jls ... ls-15.21.1