blob: 5531788ca8c02e0d42584349c139a3b559c6d07f [file] [log] [blame]
*Chapter 5*
h1. Conversions and Promotions
The organization of this chapter parallels the chapter on [Conversions and Promotions|http://java.sun.com/docs/books/jls/second_edition/html/conversions.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 in part as follows:
bq. This chapter first describes the seven categories of conversions ([§5.1|Chapter 05 Conversions#5.1], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#189955]), including the special conversions to {{String}} allowed for the string concatenation operator {{+}}. Then the five conversion contexts are described:
* Assignment conversion ([§5.2|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184206], [§15.26|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5281]) converts the type of an expression to the type of a specified variable. The conversions permitted for assignment are limited in such a way that assignment conversion never causes an exception.
* Method invocation conversion ([§5.3|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#12687], [§15.9|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#41147], [§15.12|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448]) is applied to each argument in a method or constructor invocation and, except in one case, performs the same conversions that assignment conversion does. Method invocation conversion never causes an exception.
* Casting conversion ([§5.5|Chapter 05 Conversions#5.5], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#20232]) converts the type of an expression to a type explicitly specified by a cast operator ([§15.16|Chapter 15 Expressions#15.16], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#238146]). It is more inclusive than assignment or method invocation conversion, allowing any specific conversion other than a string conversion, but certain casts to a reference type may cause an exception at run time.
* String conversion ([§5.4|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#186035], [§15.18.1|http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#39990]) allows any type to be converted to type {{String}}.
* Numeric promotion ([§5.6|Chapter 05 Conversions#5.6], [JLS|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#26917]) brings the operands of a numeric operator to a common type so that an operation can be performed.
{anchor:5.1}
h2. 5.1 Kinds of Conversion
(Cf. ??[JLS. §5.1|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25201]??.)
TO DO
{anchor:5.1.1}
h3. 5.1.1 Identity Conversions
(Cf. ??[JLS. §5.1.1|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25209]??.)
TO DO
{anchor:5.1.2}
h3. 5.1.2 Widening Primitive Conversion
(Cf. ??[JLS. §5.1.2|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25214]??.)
TO DO
{anchor:5.1.3}
h3. 5.1.3 Narrowing Primitive Conversions
(Cf. ??[JLS. §5.1.3|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25363]??.)
TO DO
{anchor:5.1.4}
h3. 5.1.4 Widening Reference Conversions
(Cf. ??[JLS. §5.1.4|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25460]??.)
TO DO
{anchor:5.1.5}
h3. 5.1.5 Narrowing Reference Conversions
(Cf. ??[JLS. §5.1.5|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25379]??.)
TO DO
{anchor:5.1.6}
h3. 5.1.6 String Conversions
(Cf. ??[JLS. §5.1.6|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#176886]??.)
TO DO
{anchor:5.1.7}
h3. 5.1.7 Forbidden Conversions
(Cf. ??[JLS. §5.1.7|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#175034]??.)
TO DO
{anchor:5.1.8}
h3. 5.1.8 Value Set Conversion
(Cf. ??[JLS. §5.1.8|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184226]??.)
TO DO
{anchor:5.2}
h2. 5.2 Assignment Conversion
(Cf. ??[JLS. §5.2|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184206]??.)
TO DO
{anchor:5.3}
h2. 5.3 Method Invocation Conversion
(Cf. ??[JLS. §5.3|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#53171]??.)
TO DO
{anchor:5.4}
h2. 5.4 String Conversion
(Cf. ??[JLS. §5.4|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#186035]??.)
TO DO
{anchor:5.5}
h2. 5.5 Casting Conversion
(Cf. ??[JLS. §5.5|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#20232]??.)
TO DO
{anchor:5.6}
h2. 5.6 Numeric Promotions
(Cf. ??[JLS. §5.6|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#26918]??.)
TO DO
{anchor:5.6.1}
h3. 5.6.1 Unary Numeric Promotion
(Cf. ??[JLS. §5.6.1|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#170952]??.)
TO DO
{anchor:5.6.2}
h3. 5.6.2 Binary Numeric Promotion
(Cf. ??[JLS. §5.6.2|http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#183615]??.)
TO DO
----
Specification [Table of Contents|Chapter 00 Contents].
The organization of this chapter parallels the chapter on [Conversions and Promotions|http://java.sun.com/docs/books/jls/second_edition/html/conversions.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].