Hamraj's question is a good one, though. Personally, I do agree that Java
should at least issue a warning when you assign a long to a float or double, or an int to a float. But it is what it is, unfortunately. Still, it's good that you're at least aware of the possibility of losing precision, since a surprising number of programmers I work with don't even know about that.
Originally posted by Serge Petunin:
When you cast an integer number to a float or a double number, you can loose precision anyway.
This isn't always true. An int will always be exactly representable in a double, since double values use 52 bits for the mantissa. But long values may indeed lose precision as you mentioned.