1

java の次のコードで:

Notification noti = nBuilder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;

この演算子 ( |=) は何のためのものですか?

4

4 に答える 4

7
noti.flags |= Notification.FLAG_AUTO_CANCEL;

意味

noti.flags = noti.flags | Notification.FLAG_AUTO_CANCEL;

どこで | それはBit wise OR operator

于 2013-07-30T10:07:02.043 に答える
3
  • | | ビットはビットまたは演算子です
  • |= noti.flags = noti.flags | Notification.FLAG_AUTO_CANCEL;

    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    noti.flags と Notification.FLAG_AUTO_CANCEL のビットごとの OR を計算し、結果を noti.flagsd に割り当てます。

于 2013-07-30T10:06:51.833 に答える
1

ビットごとの or は、次と同じです。

noti.flags = noti.flags | Notification.FLAG_AUTO_CANCEL;

オペランドのビットで「or」演算を実行します。あなたが持っていると言う

// noti.flags =                      0001011    (11 decimal)
// Notification.FLAG_AUTO_CANCEL =   1000001    (65 decimal)

// The result would be:              1001011    (75 decimal)
于 2013-07-30T10:07:07.747 に答える
1

これは、代入演算子を含むビットごとの OR です。同様にnoti.flags = noti.flags | Notification.FLAG_AUTO_CANCEL; 、ビットごとの AND には &=、ビットごとの XOR には ^=、ビットごとの NOT には ~= があります。

于 2013-07-30T10:07:10.673 に答える