Java Reference
In-Depth Information
ception, no argument expressions to the right of it will be evaluatedand
likewise for array index expressions. The order of evaluation is very spe-
cific and evaluation stops as soon as an exception is encountered.
One further detail concerns object creation with new . If insufficient
memory is available for the new object, an OutOfMemoryError exception
is thrown. This occurs before evaluation of the constructor arguments
occursbecause the value of those arguments is not needed to allocate
memory for the objectin which case those arguments won't be evalu-
ated. In contrast, when an array is created, the array dimension ex-
pressions must be evaluated first to find out how much memory to al-
locateconsequently, array creation throws the OutOfMemoryError after the
dimension expressions are evaluated.
9.3.2. Expression Type
Every expression has a type. The type of an expression is determined
by the types of its component parts and the semantics of operators.
If an arithmetic or bit manipulation operator is applied to integer values,
the result of the expression is of type int unless one or both sides are
long , in which case the result is long . The exception to this rule is that
the type of shift operator expressions are not affected by the type of
the right-hand side. All integer operations are performed in either int
or long precision, so the smaller byte and short integer types are always
promoted to int before evaluation.
If either operand of an arithmetic operator is floating point, the opera-
tion is performed in floating-point arithmetic. Such operations are done
in float unless at least one operand is a double , in which case double is
used for the calculation and result.
A + operator is a String concatenation when either operand to + is of
type String or if the left-hand side of a += is a String .
When used in an expression, a char value is converted to an int by set-
ting the top 16 bits to zero. For example, the Unicode character \uffff
 
Search WWH ::




Custom Search