= in Java / Android mean? (bit

Possible Duplicate:
Shortcut “or-assignment” (|=) operator in Java

I found the following example code in the Android SDK docs:

    boolean retValue = false;
    retValue |= mActionBarHelper.onCreateOptionsMenu(menu);
    retValue |= super.onCreateOptionsMenu(menu);

Can anyone show me equivalent code, to demonstrate what this does?

Note: I assume the method calls return a boolean value, so I like to see an example what this looks like as an if-else construct.


Shorthand for or with myself and assign to me, though it is non-short circuit or instead of logical or . As it is available as a short version of assigning and or:ing sometimes used anyway with booleans, as there is no ||=. But important note: in this case it will call both methods even though retValue might already be true

So equivalent (logic wise) statements can be several, but some would be:

boolean a = mActionBarHelper.onCreateOptionsMenu(menu);
boolean b = super.onCreateOptionsMenu(menu);
boolean retValue =  a || b;

or

boolean retValue = mActionBarHelper.onCreateOptionsMenu(menu);
retValue = super.onCreateOptionsMenu(menu) || retValue;

| applied to a boolean is just a simple boolean OR.

boolean retValue = false;
retValue = retValue | mActionBarHelper.onCreateOptionsMenu(menu);
retValue = retValue | super.onCreateOptionsMenu(menu);
链接地址: http://www.djcxy.com/p/73906.html

上一篇: 被java语法困惑

下一篇: =在Java / Android中是什么意思? (位