it doesn't compile because if you add two bytes the result in general doesn't fit into a single byte. This could easily produce an overflow so the compiler doesn't allow it.
You have to keep in mind, that the compiler ignores the values used in your code. For you it's obvious that 3+8 fits in one byte but the compiler simply doesn't know this!
It doesn't compile because of data type promotion.
Before doing addition of two bytes the byte is promoted to int. and then two integer(a,b) adds up. Now we know integer can't fit into byte. Though we know that 8 fits into byte, compiler doesn't.
To fix it you can,
1) Make a and b final.
Now, compiler is aware about the values of a and b.And also knows that they are not gonna altered.So it's not harmful to me anymore.let them allow.
2) Do casting to byte.
Here, it will caste an integer to byte and see if it fits into byte or not.If it doesn't fit then you might not get expected answer.
[ June 11, 2008: Message edited by: Vishal Pandya ]