I'm studying java by Herbert Schildt's "Java for beginners" book. It is said that, being a destiny variable compatible and sufficiently big to store an origin one, an automatic conversion is done.
That being said, an Int should be able to store an Float and vice-versa, since they both have a 4 bytes size.
public class MyClass {
public static void main(String args[]) {
int i = 10;
float f = i;
float ff = 10;
int ii = ff;
}
}
However, when compiled, this piece of code generetes the following error:
/MyClass.java:15: error: incompatible types: possible lossy conversion from float to int
int ii = ff;
^
1 error
Why is there that, being a compatible type and sufficiently big to store each other, a float can store an int but an int cannot store a float?