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!
Answer. No, the order of query parameters should not matter.
Arguments in Java are always passed-by-value. During method invocation, a copy of each argument, whether its a value or reference, is created in stack memory which is then passed to the method.
When passing an argument by reference, the method gets a reference to the object. A reference to an object is the address of the object in memory. Now, the local variable within the method is referring to the same memory location as the variable within the caller.
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.
Yes, Java guarantees that. However, this does not mean that using the code like that is a good idea: readers of your code may get thoroughly confused.
It is much cleaner to show the order explicitly:
int a = (int)rs.getDouble(k++);
int b = (int)rs.getDouble(k++);
polygon.addPoint(a, b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With