Friday, 7 June 2019

Java: Why doesn't (int) += (double) cause a "incompatible types" error?

Here's an oddity:



float a = 0;
a = a + Math.PI; // ERROR


and yet:



a += Math.PI; // OK!



even this works:



int b = 0;
b += Math.PI; // OK, too!


Why does the += operator allow lossy implicit type conversions?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...