Forums Register Login

Order of argument evaluation

+Pie Number of slices to send: Send

When this code is run, the output is:
In outer class m1()
G.s12

Why does the call to m1() execute before printing the String variable? Should't the method arguments be evaluated from left to right? Also, the return value from m1 prints after the String value.
+Pie Number of slices to send: Send
Sorry, I find your question confusing: both m1() methods have no arguments. If you mean the System.out.println() it only has one argument, and that is just the concatenation of two strings (or rather a string and int converted to string).

Are you getting confused between the return value of the function m1() in the outer class and its sideeffect of printing a line?
[ September 30, 2006: Message edited by: Barry Gaunt ]
+Pie Number of slices to send: Send
If you ask for when the argument expressions are evaluated, here is some information from JLS3
15.12.4 Runtime Evaluation of Method Invocation


At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code.
.....
The argument expressions, if any, are evaluated in order, from left to right.

 
+Pie Number of slices to send: Send
I got it, thanks a lot!
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 777 times.
Similar Threads
Special this
What is the sequence of execution?
Doubt in String class
Help!!, other Dan Chrisholm's question
inner classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:26:04.