Hello, I'm reading the rather splendid
Java 2 Sun Certified Programmer & Developer. I'm doing OK - mostly, but I can't see why a float can be compared with a long i.e. 5.0 == 5L.
Maybe it is more accurate to say a double compared to a long as 5.0 would be a double if it was assigned to a variable. But you can also do the same with a byte and short etc.
Does 5.0 == 5L work because the compiler sees the double 5.0 and casts the long to a double? Then it is effectively
testing the equality of two doubles?
I'm confused because java normally quite fussy, I mean java forces you to cast a float before accepting into a variable (you can't just say float x = 5.0) and you always get loss of precision compiler errors when implicitly casting downwards.
It must be that the bit representation of 5 (or 5L etc) and 5.0 are the same. But how can they be when one is a float?