比如notification.flags |= Notification.FLAG_AUTO_CANCEL
“|=”是啥意思?

解决方案 »

  1.   


     public static void main(String []args){   boolean False =false;
      False |= true;
      False = False | true; // & ^ | 与 或 非
      System.out.println(False);
      }
      

  2.   

    疼的程序... 
    注意提示
    // & ^ | 与 或 非应该是 False|true的结果给False
    |=
    应该和+= 工作方法一样.
      

  3.   

    在C++ 语言好像经常看到这种写法,我没记错的话,应该是
    notification.flags |= Notification.FLAG_AUTO_CANCEL
    notification.flags 和后面的 Notification.FLAG_AUTO_CANCEL做异或 
    把notification.flags除去Notification.FLAG_AUTO_CANCEL这种属性
      

  4.   

    |=一般用于二进制
    举个例子吧int a = 1,b = 2,c = 4;//0x0001,0x0010,0x0100
    a |= b;// a = 0x0011 = 3
    b |= c;// b = 0x0110 = 6
      

  5.   

    notification.flags = notification.flags|Notification.FLAG_AUTO_CANCEL
      

  6.   

    notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL
      

  7.   

    位运算,按位或 等于,notification.flags  = notification.flags | Notification.FLAG_AUTO_CANCEL比如
        int a = 5;
            int b = 3;
            System.out.println(a|=b);
    输出7,
    5 的二进制 是 0 11,
    3 的二进制 是 0 101
    按位或 运算
    有一个为1 就是1 
    结果 : 0 111  (2的二次方+加2的一次方+1) 7
      

  8.   

    notification.flags |= Notification.FLAG_AUTO_CANCEL相当于notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL跟常见的 += 一样的。int i = 0;
    i += 2;
      

  9.   

    尝试理解下下面这个示例1 代表 女的
    2 代表 男的4 代表 教授
    8 代表 禽兽那么一个实体 男禽兽 就是 flag = 2 | 8; flag 等于 10
    如果既是教授又是禽兽,那么 flag = 4 | 8,还是个男的 flag |= 2; 这个方式在很多需要一个值标识多种状态下普遍适应
      

  10.   

    c语言里边用的很多,android程序中用的也很多,很多搞嵌入式的程序员写java程序就喜欢用位运算
      

  11.   

    a>>>b 这种写法可能很多人都没见过