3

Estava fazendo algumas pesquisas e deparei com o operador em sequencia |=. Vejam:

mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;

Existe este operador no JAVA, mas não sei exatamente se segue a mesma sintaxe em outras linguagem e fiquei na dúvida.

O que significa o operador |=?

1 Resposta 1

4

Isso aplica o operador bitwise or a mBuilder.getNotification().flags e Notification.FLAG_AUTO_CANCEL e atribui o resultado a mBuilder.getNotification().flags.

É o equivalente a:

mBuilder.getNotification().flags = mBuilder.getNotification().flags | Notification.FLAG_AUTO_CANCEL;

O operador binário OR, ou disjunção binária devolve um bit 1 sempre que pelo menos um dos operandos seja '1'

Exemplo:

int a = 60; //   60 = 0011 1100 
int b = 13; //   13 = 0000 1101 
int r = (a|b) // 61 = 0011 1101

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .