I recently noticed an idiosyncrasy of Java regarding basic arithmetic operations in Java. With the following code
byte a = 3;
byte b = 4;
byte c = a * b;
I get a "type mismatch" compilation error...
Are basic arithmetic operations in Java (+
, -
, *
, /
) only performed on primitive data types of int
and higher order (long
, double
, etc.), whereas arithmetic operations on byte
and short
are first cast to int
and then evaluated?