Skip to content

关键字与运算符 ​

Java 关键字 ​

abstractassertbooleanbreakbyte
casecatchcharclassconst
continuedefaultdodoubleelse
enumextendsfinalfinallyfloat
forgotoifimplementsimport
instanceofintinterfacelongnative
newpackageprivateprotectedpublic
returnshortstaticstrictfpsuper
switchsynchronizedthisthrowthrows
transienttryvoidvolatilewhile

逻辑 / 位运算符优先级 ​

! > && > ||
~ > & > |

运算符优先级 ​

当两个运算符的优先级相同,则按照结合性的顺序求值

leveloperatordescriptionAssociativity
16[] . ()访问数组元素、对象成员、括号left to right
15++ --后置自增自减not associative
14++ -- + - ! ~前置自增自减、一元加减、一元位取反、一元逻辑非not associative
13() new转换、创建对象right to left
12* / %乘除法left to right
11+ - +加减法、字符串拼接left to right
10<< >> >>>移位运算符left to right
9< <= > >= instanceof关系运算符not associative
8== !=判断等于left to right
7&位与left to right
6^位异或left to right
5|位或left to right
4&&逻辑与left to right
3||逻辑或left to right
2?:三元运算符right to left
1= += -= *= /= %= &= ^= |= <<= >>= >>>=赋值right to left

德摩根定律 ​

!(A && B) = !A || !B
!(A || B) = !A && !B

!(A && B && C) = !A || !B || !C
!(A || B || C) = !A && !B && !C

左移右移 ​

  • <<: 左移,右边补零
  • >>: 右移,左边补最高位
  • >>>: 右移,左边补零

不懂的地方 ​

L6 PPT P21,P22