Java Reference
In-Depth Information
The value of
n
>>>
s
is
n
right-shifted
s
bit positions with zero-extension, where:
• If
n
is positive, then the result is the same as that of
n
>>
s
.
• If
n
is negative and the type of the left-hand operand is
int
, then the result is equal
to that of the expression
(
n
>>
s
) + (2 << ~
s
)
.
• If
n
is negative and the type of the left-hand operand is
long
, then the result is equal
to that of the expression
(
n
>>
s
) + (2L << ~
s
)
.
The added term
(2 << ~
s
)
or
(2L << ~
s
)
cancels out the propagated sign bit.
Note that, because of the implicit masking of the right-hand operand of a shift
operator,
~
s
as a shift distance is equivalent to
31-
s
when shifting an
int
value
and to
63-
s
when shifting a
long
value.
15.20. Relational Operators
The numerical comparison operators
<
,
>
,
<=
, and
>=
, and the
instanceof
operator, are called
the
relational operators
.
RelationalExpression:
ShiftExpression
RelationalExpression
<
ShiftExpression
RelationalExpression
>
ShiftExpression
RelationalExpression
<=
ShiftExpression
RelationalExpression
>=
ShiftExpression
RelationalExpression
instanceof
ReferenceType
The relational operators are syntactically left-associative (they group left-to-right).
However, this fact is not useful. For example,
a<b<c
parses as
(a<b)<c
, which is always
a compile-time error, because the type of
a<b
is always
boolean
and < is not an operator
on
boolean
values.
The type of a relational expression is always
boolean
.
15.20.1. Numerical Comparison Operators
<
,
<=
,
>
, and
>=
The type of each of the operands of a numerical comparison operator must be a type that is