Мда, хороший вопрос. Как выясняется, в спецификации Java предусмотрена такая штука как Binary numeric promotion:
| Цитата | 5.6.2 Binary Numeric Promotion When an operator applies binary numeric promotion to a pair of operands, each of which must denote a value that is convertible to a numeric type, the following rules apply, in order, using widening conversion (§5.1.2) to convert operands as necessary:
- If any of the operands is of a reference type, unboxing conversion (§5.1.8) is performed. Then:
- If either operand is of type double, the other is converted to double.
- Otherwise, if either operand is of type float, the other is converted to float.
- Otherwise, if either operand is of type long, the other is converted to long.
- Otherwise, both operands are converted to type int.
|
Источник: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#170983
А о том, что Binary Numeric Promotion применяется в том числе к результату арифметического сложения, говорится здесь:
| Цитата | 15.18.2 Additive Operators (+ and -) for Numeric Types The binary + operator performs addition when applied to two operands of numeric type, producing the sum of the operands. The binary - operator performs subtraction, producing the difference of two numeric operands.
Binary numeric promotion is performed on the operands (§5.6.2). The type of an additive expression on numeric operands is the promoted type of its operands. If this promoted type is int or long, then integer arithmetic is performed; if this promoted type is float or double, then floating-point arithmetic is performed.
|
Источник: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.2
Вот так вота, век живи - век учись Я вот тоже не знал, так что спасибо за интересный пример.
|