This content has been marked as final. Show 4 replies
If all floating point literals in java are automatically a double typeNo, the f postfix makes a literal of the float (and not double) type.
float a = 1.9f;
Ok thanks for the answer, it was pretty obvious really! Its still early...
Can this question be marked as answered?
You should be able to mark the correct answer yourself, but you need to have mark the thread as question when you created it (I think you didn't).
Also note that if you assign a float to a double, it gets automatically widened to a double. This can be done because no precision is lost, but it doesn't mean a float-is-actually-a-double.
float f = 1.0f; double d = f; // valid automatically converts float value to double value f = d; // error: not allowed since precision would be lost f = (float) d; // but can cast explicitly to say that we don't mind the loss
Also, those aren't references.