10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

EXPRESSIONS Conditional-Or Operator || 15.24<br />

For &, the result value is true if both operand values are true; otherwise, the<br />

result is false.<br />

For ^, the result value is true if the operand values are different; otherwise,<br />

the result is false.<br />

For |, the result value is false if both operand values are false; otherwise,<br />

the result is true.<br />

15.23 Conditional-And Operator &&<br />

<strong>The</strong> && operator is like & (§15.22.2), but evaluates its right-hand operand only if<br />

the value of its left-hand operand is true. It is syntactically left-associative (it<br />

groups left-to-right). It is fully associative with respect to both side effects and<br />

result value; that is, for any expressions a, b, and c, evaluation of the expression<br />

((a)&&(b))&&(c) produces the same result, with the same side effects occurring<br />

in the same order, as evaluation of the expression (a)&&((b)&&(c)).<br />

ConditionalAndExpression:<br />

InclusiveOrExpression<br />

ConditionalAndExpression && InclusiveOrExpression<br />

Each operand of && must be of type boolean or Boolean, or a compile-time<br />

error occurs. <strong>The</strong> type of a conditional-and expression is always boolean.<br />

At run time, the left-hand operand expression is evaluated first; if the result<br />

has type Boolean, it is subjected to unboxing conversion (§5.1.8); if the resulting<br />

value is false, the value of the conditional-and expression is false and the righthand<br />

operand expression is not evaluated. If the value of the left-hand operand is<br />

true, then the right-hand expression is evaluated; if the result has type Boolean,<br />

it is subjected to unboxing conversion (§5.1.8); the resulting value becomes the<br />

value of the conditional-and expression. Thus, && computes the same result as &<br />

on boolean operands. It differs only in that the right-hand operand expression is<br />

evaluated conditionally rather than always.<br />

DRAFT<br />

15.24 Conditional-Or Operator ||<br />

<strong>The</strong> || operator is like | (§15.22.2), but evaluates its right-hand operand only if<br />

the value of its left-hand operand is false. It is syntactically left-associative (it<br />

groups left-to-right). It is fully associative with respect to both side effects and<br />

result value; that is, for any expressions a, b, and c, evaluation of the expression<br />

((a)||(b))||(c) produces the same result, with the same side effects occurring<br />

in the same order, as evaluation of the expression (a)||((b)||(c)).<br />

509

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!