operator's side
TRANSCRIPT
演算子とは?
!
“ In computer programming and at the command line, an operator is an object that is capable of manipulating a value or operator. ”
引用元 : http://www.computerhope.com/jargon/o/operator.htm
前置と後置を比較!
int a = 0; int b = a++; // b -> 0 !
Code: 0: iconst_0 1: istore_1 2: iload_1 3: iinc 1, 1 6: istore_2
!
int a = 0; int b = ++a; // b -> 1 !
Code: 0: iconst_0 1: istore_1 2: iinc 1, 1 5: iload_1 6: istore_2
単体で使う場合
int a = 0; !
a++; ++a; a += 1;
Code: 0: iconst_0 1: istore_1 2: iinc 1, 1 5: iinc 1, 1 8: iinc 1, 1
内部ではどれも一緒っぽい
短絡評価の利用
// array.length == 10 とする for (int i = 0; i < 20; i++) if (i < 10 && array[i] % 2 == 0) { /* 処理 */ } !
i が 10未満の場合のみ array[i] にアクセスする
int型での利用
• a が奇数かどうか評価
int a = 11; // 0b1011
if ((a & 1) == 1)
• LSBが1かどうか評価している
0b1011 AND ) 0b0001
0b0001
複合代入演算子
• 自己代入を行う演算子
• +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, |=, ^=
• a += 1; -> a = a + 1;
• b /= c - 2; -> b = b / (c - 2);
参考URL• Java演算子・式の評価 : http://www.ne.jp/asahi/hishidama/home/tech/java/expression.html
• Javaの道 > Java基本 : http://www.javaroad.jp/index_basic.htm
• バイトコード : http://www.ne.jp/asahi/hishidama/home/tech/java/bytecode.html
• Java入門 | Byte Code : http://msugai.fc2web.com/java/perform/byte.html