java error possible loss of precision

July 8, 2012 at 19:46:12
Specs: Windows XP
here is my script:

int a = 5
byte b = a ++

when i run it, my IDE gives me an error that says possible loss of precision. i do need 'a' to be an int and 'b' to be a byte. how do you fix this??

See More: java error possible loss of precision

Report •

July 9, 2012 at 00:39:55
If you insist that a is an int and b is a byte then you can't fix it. Consider the case when a = 255. Then the code will set a to 256 and b to 0. That is the loss of precision. Or, even worse, if a = 254 then after the code you will have a = 255 and b = -1.

If it doesn't matter to you, and is that result is what you require, then you can ignore the warning ( or use a cast to suppress it).

Report •

July 10, 2012 at 18:01:15
yeah, i decided a could be a byte, but it is still giving me the same error for this script:

byte a = 5
byte b = a++

Report •

Related Solutions

Ask Question