Java Reference
In-Depth Information
Table A.2.8
Other operators.
Operator
Name
Description
Conditional
Operator
The first operand -
boolean
-isaBoolean variable or
expression.
First this Boolean operand is evaluated. If it is
true
then the second operator is evaluated and x is set to
that value.
If the Boolean operator is
false
, then the third
operand is evaluated and x is set to that value.
x=
boolean
?y:x
(
primitive type
)
Type Cast
To assign a value of one primitive numeric type to a
more narrow type, e.g.
long
to
int
,anexplicit cast
operation is required, e.g.
long a
=
5;
int b = (int)a;
Table A.2.9
Operator precedence. The larger the number, the higher the precedence.
1
2
3
4
567 8
9
0 11
12
13
14
15
=
||
|
^
==
<
<<
.
?:
&&
&
+
*
new
++x
*
=
!
= = >
-
(
type
) x
[]
/
/
=
<
>>>
%
+x
(
args
)
%
=
<=
-x
x++
+
=
~
x--
-
=
!
<<=
>>=
>>>=
&=
^=
|
=
Notes:
•
(
type
)
refers to the casting operator.
•
“.
„
is the object member access operator.
•
[]
is the array access operator.
•
(
args
)
indicates the invocation of a method.
• In column 11, the
+
and
--
refer to binary addition and subtraction. Also, the
+
refers to the string
concatenation operator. In column 14, the
+
and
--
refer to the unary operations
+x
and
-x
and specify
the sign of the value.
•|,
^
, and
&
refer to both the bitwise and Boolean operators.
Search WWH ::
Custom Search