DRAFT
NoCastIfSameSize
Incorrect
If a variable is at least as big (bit-width) as a value, then no cast is needed to a assign the value to the variable
Correct
CorrectionHere is what's right.
Here is what's right.
While the size is a relevant aspect when deciding whether or not a cast is needed, it is not the only aspect. It is not possible to assign a float
to an int
(even though both are 32 bits wide), or a double
to a long
(both 64 bits) without a cast.
Floating-point numbers have a much larger range than the integral numbers, and thus trying to store them into an integral variable might lead to a dramatically different value.
int i = 3F; // wrong
double d = 3D; // wrong
Language
Java