Java的操作员:| =按位OR和分配例子 [英] Java Operators : |= bitwise OR and assign example

查看:197
本文介绍了Java的操作员:| =按位OR和分配例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚经历code有人写,我看到 | = 的使用,Java的运营商仰视,它表明按位或并指定操作,任何人都可以解释给我它的一个例子吗?

下面是code,上面写着的:

 为(字符串搜索:textSearch.getValue())
         比赛| = field.contains(搜索);


解决方案

  A | = B;

是相同的

  A =(A | B);

它计算的按位或两个操作数,而受让人的结果给左操作数。

要解释你的榜样code:

 为(字符串搜索:textSearch.getValue())
    比赛| = field.contains(搜索);

我presume 匹配布尔;这意味着,按位运算符行为相同,逻辑运算符。

在循环的每次迭代中,它 s ^ 匹配的当前值与任何从返回 field.contains()。这有其设置为真正如果是已经成为事实,如果 field.contains()返回true。

所以,如果计算出的任何的调用 field.contains(),在整个循环,又回到了<$ C $的C>真正

I just going through code someone has written and I saw |= usage, looking up on Java operators, it suggests bitwise or and assign operation, can anyone explain and give me an example of it?

Here is the code that read it:

    for (String search : textSearch.getValue())
         matches |= field.contains(search);

解决方案

a |= b;

is the same as

a = (a | b);

It calculates the bitwise OR of the two operands, and assigns the result to the left operand.

To explain your example code:

for (String search : textSearch.getValue())
    matches |= field.contains(search);

I presume matches is a boolean; this means that the bitwise operators behave the same as logical operators.

On each iteration of the loop, it ORs the current value of matches with whatever is returned from field.contains(). This has the effect of setting it to true if it was already true, or if field.contains() returns true.

So, it calculates if any of the calls to field.contains(), throughout the entire loop, has returned true.

这篇关于Java的操作员:| =按位OR和分配例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆