blob: 3445042faf9c5d1b55e58134426c21fca8b1f2a2 [file] [log] [blame]
*Chapter 15*
h1. Expressions
The organization of this chapter parallels the chapter on [Expressions|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html] in the [Java Language Specification (second edition)|http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html], which begins as follows:
bq. Much of the work in a program is done by evaluating ??expressions??, either for their side effects, 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.
bq. This chapter specifies the meanings of expressions and the rules for their evaluation.
{anchor:15.1}
h2. 15.1 Evaluation, Denotation, and Result
(Cf. ??[JLS. §15.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#228862]??.)
TO DO
{anchor:15.2}
h2. 15.2 Variables as Values
(Cf. ??[JLS. §15.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#229188]??.)
TO DO
{anchor:15.3}
h2. 15.3 Type of an Expression
(Cf. ??[JLS. §15.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#198550]??.)
TO DO
{anchor:15.4}
h2. 15.4 FP-strict Expressions
(Cf. ??[JLS. §15.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#249198]??.)
TO DO
{anchor:15.5}
h2. 15.5 Expressions and Run-Time Checks
(Cf. ??[JLS. §15.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#290072]??.)
TO DO
{anchor:15.6}
h2. 15.6 Normal and Abrupt Completion of Evaluation
(Cf. ??[JLS. §15.6|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#79449]??.)
TO DO
{anchor:15.7}
h2. 15.7 Evaluation Order
(Cf. ??[JLS. §15.7|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4779]??.)
TO DO
{anchor:15.7.1}
h3. 15.7.1 Evaluate Left-Hand Operand First
(Cf. ??[JLS. §15.7.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#18498]??.)
TO DO
{anchor:15.7.2}
h3. 15.7.2 Evaluate Operands before Operation
(Cf. ??[JLS. §15.7.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#18740]??.)
TO DO
{anchor:15.7.3}
h3. 15.7.3 Evaluation Respects Parentheses and Precedence
(Cf. ??[JLS. §15.7.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23213]??.)
TO DO
{anchor:15.7.4}
h3. 15.7.4 Argument Lists are Evaluated Left-to-Right
(Cf. ??[JLS. §15.7.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23789]??.)
TO DO
{anchor:15.7.5}
h3. 15.7.5 Evaluation Order for Other Expressions
(Cf. ??[JLS. §15.7.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23451]??.)
TO DO
{anchor:15.8}
h2. 15.8 Primary Expressions
(Cf. ??[JLS. §15.8|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#36225]??.)
TO DO
{anchor:15.8.1}
h3. 15.8.1 Lexical Literals
(Cf. ??[JLS. §15.8.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#36407]??.)
TO DO
{anchor:15.8.2}
h3. 15.8.2 Class Literals
(Cf. ??[JLS. §15.8.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251530]??.)
TO DO
{anchor:15.8.3}
h3. 15.8.3 <code>this </h3>
(Cf. ??[JLS. &#167;15.8.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251519]??.)
TO DO
{anchor:15.8.4}
h3. 15.8.4 Qualified <code>this</h3>
(Cf. ??[JLS. &#167;15.8.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251603]??.)
TO DO
{anchor:15.8.5}
h3. 15.8.5 Parenthesized Expressions
(Cf. ??[JLS. &#167;15.8.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#236822]??.)
TO DO
{anchor:15.9}
h2. 15.9 Class Instance Creation Expressions
(Cf. ??[JLS. &#167;15.9|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#41147]??.)
TO DO
{anchor:15.9.1}
h3. 15.9.1 Determining the Class being Instantiated
(Cf. ??[JLS. &#167;15.9.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23745]??.)
TO DO
{anchor:15.9.2}
h3. 15.9.2 Determining Enclosing Instances
(Cf. ??[JLS. &#167;15.9.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#253028]??.)
TO DO
{anchor:15.9.3}
h3. 15.9.3 Choosing the Constructor and its Arguments
(Cf. ??[JLS. &#167;15.9.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#253097]??.)
TO DO
{anchor:15.9.4}
h3. 15.9.4 Run-time Evaluation of Class Instance Creation Expressions
(Cf. ??[JLS. &#167;15.9.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251881]??.)
TO DO
{anchor:15.9.5}
h3. 15.9.5 Anonymous Class Declarations
(Cf. ??[JLS. &#167;15.9.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#252986]??.)
TO DO
{anchor:15.9.5.1}
h4. 15.9.5.1 Anonymous Constructors
(Cf. ??[JLS. &#167;15.9.5.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#253002]??.)
TO DO
{anchor:15.9.6}
h3. 15.9.6 Example: Evaluation Order and Out-of-Memory Detection
(Cf. ??[JLS. &#167;15.9.6|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#36687]??.)
TO DO
{anchor:15.10}
h2. 15.10 Array Creation Expressions
(Cf. ??[JLS. &#167;15.10|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#46168]??.)
TO DO
{anchor:15.10.1}
h3. 15.10.1 Run-time Evaluation of Array Creation Expressions
(Cf. ??[JLS. &#167;15.10.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23605]??.)
TO DO
{anchor:15.10.2}
h3. 15.10.2 Example: Array Creation Evaluation Order
(Cf. ??[JLS. &#167;15.10.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#264396]??.)
TO DO
{anchor:15.10.3}
h3. 15.10.3 Example: Array Creation and Out-of-Memory Detection
(Cf. ??[JLS. &#167;15.10.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#36736]??.)
TO DO
{anchor:15.11}
h2. 15.11 Field Access Expressions
(Cf. ??[JLS. &#167;15.11|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#41267]??.)
TO DO
{anchor:15.11.1}
h3. 15.11.1 Field Access Using a Primary
(Cf. ??[JLS. &#167;15.11.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#37055]??.)
TO DO
{anchor:15.11.2}
h3. 15.11.2 Accessing Superclass Members using <code>super</h3>
(Cf. ??[JLS. &#167;15.11.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20860]??.)
TO DO
{anchor:15.12}
h2. 15.12 Method Invocation Expressions
(Cf. ??[JLS. &#167;15.12|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448]??.)
TO DO
{anchor:15.12.1}
h3. 15.12.1 Compile-Time Step 1: Determine Class or Interface to Search
(Cf. ??[JLS. &#167;15.12.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#21692]??.)
TO DO
{anchor:15.12.2}
h3. 15.12.2 Compile-Time Step 2: Determine Method Signature
(Cf. ??[JLS. &#167;15.12.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#19915]??.)
TO DO
{anchor:15.12.2.1}
h4. 15.12.2.1 Find Methods that are Applicable and Accessible
(Cf. ??[JLS. &#167;15.12.2.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#18427]??.)
TO DO
{anchor:15.12.2.2}
h4. 15.12.2.2 Choose the Most Specific Method
(Cf. ??[JLS. &#167;15.12.2.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#272863]??.)
TO DO
{anchor:15.12.2.3}
h4. 15.12.2.3 Example: Overloading Ambiguity
(Cf. ??[JLS. &#167;15.12.2.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#21712]??.)
TO DO
{anchor:15.12.2.4}
h4. 15.12.2.4 Example: Return Type Not Considered
(Cf. ??[JLS. &#167;15.12.2.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#21727]??.)
TO DO
{anchor:15.12.2.5}
h4. 15.12.2.5 Example: Compile-Time Resolution
(Cf. ??[JLS. &#167;15.12.2.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#29775]??.)
TO DO
{anchor:15.12.3}
h3. 15.12.3 Compile-Time Step 3: Is the Chosen Method Appropriate?
(Cf. ??[JLS. &#167;15.12.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23617]??.)
TO DO
{anchor:15.12.4}
h3. 15.12.4 Runtime Evaluation of Method Invocation
(Cf. ??[JLS. &#167;15.12.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#45677]??.)
TO DO
{anchor:15.12.4.1}
h4. 15.12.4.1 Compute Target Reference (If Necessary)
(Cf. ??[JLS. &#167;15.12.4.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#38359]??.)
TO DO
{anchor:15.12.4.2}
h4. 15.12.4.2 Evaluate Arguments
(Cf. ??[JLS. &#167;15.12.4.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#21593]??.)
TO DO
{anchor:15.12.4.3}
h4. 15.12.4.3 Check Accessibility of Type and Method
(Cf. ??[JLS. &#167;15.12.4.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#45453]??.)
TO DO
{anchor:15.12.4.4}
h4. 15.12.4.4 Locate Method to Invoke
(Cf. ??[JLS. &#167;15.12.4.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#45606]??.)
TO DO
{anchor:15.12.4.5}
h4. 15.12.4.5 Create Frame, Synchronize, Transfer Control
(Cf. ??[JLS. &#167;15.12.4.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39078]??.)
TO DO
{anchor:15.12.4.6}
h4. 15.12.4.6 Example: Target Reference and Static Methods
(Cf. ??[JLS. &#167;15.12.4.6|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39122]??.)
TO DO
{anchor:15.12.4.7}
h4. 15.12.4.7 Example: Evaluation Order
(Cf. ??[JLS. &#167;15.12.4.7|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23837]??.)
TO DO
{anchor:15.12.4.8}
h4. 15.12.4.8 Example: Overriding
(Cf. ??[JLS. &#167;15.12.4.8|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#239650]??.)
TO DO
{anchor:15.12.4.9}
h4. 15.12.4.9 Example: Method Invocation using super
(Cf. ??[JLS. &#167;15.12.4.9|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#239751]??.)
TO DO
{anchor:15.13}
h2. 15.13 Array Access Expressions
(Cf. ??[JLS. &#167;15.13|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#239587]??.)
TO DO
{anchor:15.13.1}
h3. 15.13.1 Runtime Evaluation of Array Access
(Cf. ??[JLS. &#167;15.13.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23958]??.)
TO DO
{anchor:15.13.2}
h3. 15.13.2 Examples: Array Access Evaluation Order
(Cf. ??[JLS. &#167;15.13.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23906]??.)
TO DO
{anchor:15.14}
h2. 15.14 Postfix Expressions
(Cf. ??[JLS. &#167;15.14|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#36254]??.)
TO DO
{anchor:15.14.1}
h3. 15.14.1 Postfix Increment Operator ++
(Cf. ??[JLS. &#167;15.14.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#249305]??.)
TO DO
{anchor:15.14.2}
h3. 15.14.2 Postfix Decrement Operator --
(Cf. ??[JLS. &#167;15.14.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4987]??.)
TO DO
{anchor:15.15}
h2. 15.15 Unary Operators
(Cf. ??[JLS. &#167;15.15|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4990]??.)
TO DO
{anchor:15.15.1}
h3. 15.15.1 Prefix Increment Operator ++
(Cf. ??[JLS. &#167;15.15.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5002]??.)
TO DO
{anchor:15.15.2}
h3. 15.15.2 Prefix Decrement Operator --
(Cf. ??[JLS. &#167;15.15.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#239136]??.)
TO DO
{anchor:15.15.3}
h3. 15.15.3 Unary Plus Operator +
(Cf. ??[JLS. &#167;15.15.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#24924]??.)
TO DO
{anchor:15.15.4}
h3. 15.15.4 Unary Minus Operator -
(Cf. ??[JLS. &#167;15.15.4|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#236345]??.)
TO DO
{anchor:15.15.5}
h3. 15.15.5 Bitwise Complement Operator ~
(Cf. ??[JLS. &#167;15.15.5|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39739]??.)
TO DO
{anchor:15.15.6}
h3. 15.15.6 Logical Complement Operator !
(Cf. ??[JLS. &#167;15.15.6|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#13350]??.)
TO DO
{anchor:15.16}
h2. 15.16 Cast Expressions
(Cf. ??[JLS. &#167;15.16|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#238146]??.)
TO DO
{anchor:15.17}
h2. 15.17 Multiplicative Operators
(Cf. ??[JLS. &#167;15.17|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#239829]??.)
TO DO
{anchor:15.17.1}
h3. 15.17.1 Multiplication Operator *
(Cf. ??[JLS. &#167;15.17.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5036]??.)
TO DO
{anchor:15.17.2}
h3. 15.17.2 Division Operator /
(Cf. ??[JLS. &#167;15.17.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5047]??.)
TO DO
{anchor:15.17.3}
h3. 15.17.3 Remainder Operator %
(Cf. ??[JLS. &#167;15.17.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#24956]??.)
TO DO
{anchor:15.18}
h2. 15.18 Additive Operators
(Cf. ??[JLS. &#167;15.18|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#15749]??.)
TO DO
{anchor:15.18.1}
h3. 15.18.1 String Concatenation Operator +
(Cf. ??[JLS. &#167;15.18.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39990]??.)
TO DO
{anchor:15.18.1.1}
h4. 15.18.1.1 String Conversion
(Cf. ??[JLS. &#167;15.18.1.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40220]??.)
TO DO
{anchor:15.18.1.2}
h4. 15.18.1.2 Optimization of String Concatenation
(Cf. ??[JLS. &#167;15.18.1.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40226]??.)
TO DO
{anchor:15.18.1.3}
h4. 15.18.1.3 Examples of String Concatenation
(Cf. ??[JLS. &#167;15.18.1.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40423]??.)
TO DO
{anchor:15.18.2}
h3. 15.18.2 Additive Operators (+ and -) for Numeric Types
(Cf. ??[JLS. &#167;15.18.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#13510]??.)
TO DO
{anchor:15.19}
h2. 15.19 Shift Operators
(Cf. ??[JLS. &#167;15.19|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5121]??.)
TO DO
{anchor:15.20}
h2. 15.20 Relational Operators
(Cf. ??[JLS. &#167;15.20|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40641]??.)
TO DO
{anchor:15.20.1}
h3. 15.20.1 Numerical Comparison Operators &lt;, &lt;=, &gt;, and &gt;=
(Cf. ??[JLS. &#167;15.20.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#153654]??.)
TO DO
{anchor:15.20.2}
h3. 15.20.2 Type Comparison Operator instanceof
(Cf. ??[JLS. &#167;15.20.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#80291]??.)
TO DO
{anchor:15.21}
h2. 15.21 Equality Operators
(Cf. ??[JLS. &#167;15.21|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5192]??.)
TO DO
{anchor:15.21.1}
h3. 15.21.1 Numerical Equality Operators ==&#32;and !=
(Cf. ??[JLS. &#167;15.21.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5198]??.)
TO DO
{anchor:15.21.2}
h3. 15.21.2 Boolean Equality Operators ==&#32;and !=
(Cf. ??[JLS. &#167;15.21.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#80389]??.)
TO DO
{anchor:15.21.3}
h3. 15.21.3 Reference Equality Operators ==&#32;and !=
(Cf. ??[JLS. &#167;15.21.3|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#236163]??.)
TO DO
{anchor:15.22}
h2. 15.22 Bitwise and Logical Operators
(Cf. ??[JLS. &#167;15.22|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5228]??.)
TO DO
{anchor:15.22.1}
h3. 15.22.1 Integer Bitwise Operators &amp;, ^, and |
(Cf. ??[JLS. &#167;15.22.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5233]??.)
TO DO
{anchor:15.22.2}
h3. 15.22.2 Boolean Logical Operators &amp;, ^, and |
(Cf. ??[JLS. &#167;15.22.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5242]??.)
TO DO
{anchor:15.23}
h2. 15.23 Conditional-And Operator &amp;&amp;
(Cf. ??[JLS. &#167;15.23|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5247]??.)
TO DO
{anchor:15.24}
h2. 15.24 Conditional-Or Operator ||
(Cf. ??[JLS. &#167;15.24|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#54532]??.)
TO DO
{anchor:15.25}
h2. 15.25 Conditional Operator ?&#32;:
(Cf. ??[JLS. &#167;15.25|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#290293]??.)
TO DO
{anchor:15.26}
h2. 15.26 Assignment Operators
(Cf. ??[JLS. &#167;15.26|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5281]??.)
TO DO
{anchor:15.26.1}
h3. 15.26.1 Simple Assignment Operator =
(Cf. ??[JLS. &#167;15.26.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5295]??.)
TO DO
{anchor:15.26.2}
h3. 15.26.2 Compound Assignment Operators
(Cf. ??[JLS. &#167;15.26.2|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5304]??.)
TO DO
{anchor:15.27}
h2. 15.27 Expression
(Cf. ??[JLS. &#167;15.27|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5309]??.)
TO DO
{anchor:15.28}
h2. 15.28 Constant Expression
(Cf. ??[JLS. &#167;15.28|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#236323]??.)
TO DO
----
Specification [Table of Contents|Chapter 00 Contents].
The organization of this chapter parallels the chapter on [Expressions|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html] in the [Java Language Specification (second edition)|http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html].
The original of this specification is at [http://docs.codehaus.org/display/GroovyJSR].