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:
• A variable (§ 4.12 ) (in C, this would be called an lvalue )
• A value (§ 4.2 , § 4.3 )
• 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
a method that does not return a value, that is, a method declared void 8.4 ) . Such an ex-
pression can be used only as an expression statement (§ 14.8 ) , because every other context in
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 set conversion (§ 5.1.13 ) is applied to the result of every expression that produces a
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.
• An annotation (§ 9.7 ) of a package or of a top level type declaration.
Search WWH ::




Custom Search