How are primitives in Java?

Good day
In the book I read that the default literal is int.
By default, Java assumes you are defining an int value with a numeric literal.

short i = 5;
5 here - in fact it is int?
That's why it compiles?
byte a = (int)0L;

but it is not?
byte a = (long)0L;
April 19th 20 at 12:10
1 answer
April 19th 20 at 12:12
Because the default for calculations the compiler converts boolean, byte, char, short as an int type. In the case of type long, the compiler will assume that you have explicitly set the type that does not fit into the range of byte values:

Actual type Computational type
boolean int
byte int 
char int 
short int 
int int 
float float 
reference reference 
returnAddress returnAddress 
long long 
double double
Thank you very much! - Aida.Stokes commented on April 19th 20 at 12:15

Find more questions by tags Java