A value of a given type cannot be assigned to a variable of a data type with a smaller size, because we would risk to lose information. Moreover, a floating point value cannot be assigned to an integer variable.
The following table describes whether the assignment a=b is legal, for each possible type for a (on the rows) and b (on the columns).
a=b | byte | short | int | long | float | double |
byte | OK | ERROR | ERROR | ERROR | ERROR | ERROR |
short | OK | OK | ERROR | ERROR | ERROR | ERROR |
int | OK | OK | OK | ERROR | ERROR | ERROR |
long | OK | OK | OK | OK | ERROR | ERROR |
float | OK | OK | OK | OK | OK | ERROR |
double | OK | OK | OK | OK | OK | OK |
Example: