What does the |= operator do in Java?

前端 未结 6 735
暗喜
暗喜 2020-12-06 10:15

While reading the Android guide to Notifications, I stumbled across this:

Adding vibration

You can alert the user with th

6条回答
  •  盖世英雄少女心
    2020-12-06 10:46

    It is a short hand notation for performing a bitwise OR and an assignment in one step.

    x |= y is equivalent to x = x | y

    This can be done with many operators, for example:

    x += y
    x -= y
    x /= y
    x *= y
    etc.
    

    An example of the bitwise OR using numbers.. if either bit is set in the operands the bit will be set in the result. So, if:

    x = 0001 and
    y = 1100 then
    --------
    r = 1101
    

提交回复
热议问题