Java Reference
In-Depth Information
Chapter 15. Expressions
Much of the work in a program is done by evaluating
expressions
, either for their side ef-
fects, such as assignments to variables, or for their values, which can be used as arguments
or operands in larger expressions, or to affect the execution sequence in statements, or both.
This chapter specifies the meanings of expressions and the rules for their evaluation.
15.1. Evaluation, Denotation, and Result
When an expression in a program is
evaluated
(
executed
), the result denotes one of three
things:
• Nothing (the expression is said to be void)
Evaluation of an expression can also produce side effects, because expressions may contain
embedded assignments, increment operators, decrement operators, and method invocations.
An expression denotes nothing if and only if it is a method invocation (§
15.12
) that invokes
which an expression can appear requires the expression to denote something. An expression
statement that is a method invocation may also invoke a method that produces a result; in
this case the value returned by the method is quietly discarded.
value.
Each expression occurs in either:
• The declaration of some (class or interface) type that is being declared: in a field
initializer, in a static initializer, in an instance initializer, in a constructor declara-
tion, in an annotation, or in the code for a method.