View Single Post
Old Oct 12th, 2007, 11:08 PM   #10
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 12 Harakim is on a distinguished road
There are three things to be taken from this:
1) PrintStream.println() converts whatever is inside to a string...basically
2) Operations inside a function call's parenthesis are evaulated before the call.
3) Operations in Java are evaluated from left to right.
4) When an operation between two types happens, the lesser type is promoted to the greater type.


The operators in Java are evaluated from left to right:
EXAMPLE: 1 + 2 + 3 + "a" == ((1 + 2) + 3) + "a"
EXAMPLE: 1 + 2 + 3 + "a" != 1 + (2 + (3 + "a"))
More specific examples are included at the bottom

More than you want to know about type promotions
When an operation between two types happens, the lesser type is promoted to the greater type:
EXAMPLE: byte b = (byte)1;
              int a = b + 13434;  //b becomes an int
EXAMPLE: int i = 10;
EXAMPLE: String s = i + "cat"; // i becomes "10", the string


System.out.println( 1 + 2 );
-->
1 + 2;
System.out.println( 3 );


System.out.println( "a" + 1 + 2 );
-->
"a" + 1
"a1" + 2
System.out.println( "a12" );

System.out.println( 1 + 2 + "a" );
-->
1 + 2
3 + "a"
System.out.println( "3a" );
Harakim is offline   Reply With Quote