Wednesday, 7 August 2013

Eclipse and Java - short plus short is an int

Eclipse and Java - short plus short is an int

I have three short variables. When I add two together and assign the
result to the third, eclipse tells me that I need to cast it to a short !
short sFirst, sSecond, sThird;
sFirst = 10;
sSecond = 20;
sThird = sFirst + sSecond;
Hovever, when I do a simple assignment followed by an incremental
assignment, all is fine.
short sFirst, sSecond, sThird;
sFirst = 10;
sSecond = 20;
sThird = sFirst;
sThird += sSecond;
Why is this ?

No comments:

Post a Comment