Search code examples
javamethodsargument-passingorder-of-execution

Is Passing Arguments to a method always ordered left to right in java?


I'll call a method with two arguments, but i'll use k++ like this:

polygon.addPoint((int)rs.getDouble( k++),(int)rs.getDouble( k++ ));

Actually i want to be sure that jvm executes first argument first, then the second one. If somehow the order will change, arguments would be passed wrong order.

Thanks a lot!


Solution

  • Yes, the arguments are guaranteed to be evaluated left-to-right. Any compiler complying to JLS rules should follow that. This is mentioned in JLS §15.7.4:

    In a method or constructor invocation or class instance creation expression, argument expressions may appear within the parentheses, separated by commas. Each argument expression appears to be fully evaluated before any part of any argument expression to its right.