Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Order of argument evaluation

 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it, thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic