According to the JLS:Fascinating! It's fun learning something new. :)
A compound assignment expression of the formE1 op= E2
is equivalent toE1 = (T)((E1) op (E2))
, whereT
is the type ofE1
, except thatE1
is evaluated only once.
Soint x = 0;
x += Math.pow(y,z);
is equivalent toint x = 0;
x = (int) (x + Math.pow(y,z));
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.26.2
This is my own little soapbox. Disclaimer: It is not written by someone you think you know, but by her evil twin. Absolutely nothing said here is true. Everything, including the last statement, is a complete work of fiction. This blog is completely boring, and includes entries on when I last washed my dishes, how many pairs of socks I've crocheted, and the occasional rant. These are not the droids you're looking for. Move along.
Wednesday, November 10, 2010
Learned something new today...
When I was stumped, a co-worker found the answer:
Subscribe to:
Post Comments (Atom)
2 comments:
And my comment is o_O
What it means is that the following works:
int x = 1;
double y = 3.14;
x += y;
where you might think it should complain about "possible loss of precision".
Post a Comment