Tuesday, 11 October 2016

java - Primitives float and double: why does f+=d not result in Type Mismatch Error?



Possible Duplicate:
Java += operator






Code example:



    double d = 1;
float f = 2;
f += d; // no error?

f = f+d; // type mismatch error, should be f = (float) (f+d);


So why does f+=d not produce an error (not even at runtime), although this would decrease the accuracy of d?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...