Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: lang design question
|
Posted: Apr 24, 2003 11:29 AM
|
|
This is another good reason to use the Jikes compiler instead of Javac: besides being drastically faster, it gives better and more detailed error messages. (You can easily find the Jikes compiler by searching on Google).
When you multiply the two bytes, the temporary result is an int. That is, the bytes are promoted to ints in order to perform the multiplication. You can find plenty of details about this on chapters of Inside the Java Virtual Machine book on this web site.
The real problem is that you are assigning a int value to a byte variable. Notice that you get the same error message from this code:
int i = 1;
byte b = i;
So really all you need to do is cast the int back to a byte, by doing something like this:
byte a = 1, b = 2;
byte c = (byte)(a*b);
|
|