Java tips, observations, bugs and problems from the world of Spring, Weblogic, Oracle, MySQL and many other technologies...
Saturday, 22 January 2011
Arithmetic Promotion
In a calculation everything is promoted to an int or larger.
1. byte b = 6;
2. b = b + 6;
Line 2 will fail because b + 6 will create an int which is being assigned to a byte
Line 1 will pass although strictly speaking an int is being assigned to a byte. (It's a fudge that makes literals work more easily).
No comments:
Post a comment