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?
About Question com.enthuware.ets.scjp.v6.2.340 :
Moderator: admin
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.340 :
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 -
"Binary Numeric Promotion" of Java Language Specification. To quote -
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.1Otherwise, if either operand is of type float, the other is converted to float.
Who is online
Users browsing this forum: No registered users and 4 guests