Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of execution of parameters guarantees in Java?

Given the following function call in C:

fooFunc( barFunc(), bazFunc() ); 

The order of execution of barFunc and BazFunc is not specified, so barFunc() may be called before bazFunc() or bazFunc() before barFunc() in C.

Does Java specify an order of execution of function argument expressions or like C is that unspecified?

like image 614
tpdi Avatar asked Feb 04 '10 17:02

tpdi


People also ask

What is order of parameters in Java?

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.

Does order of parameters in Java matter?

The formal parameters are specified as a list, so for "the formal parameter types of M and N" to be the same, they must be the same list and lists are order-dependant. Since the correspondance in 3 is order dependent, the order of type parameters also matters.

Does order matter for parameters?

An example would be ADD : ADD(1,2) and ADD(2,1) can be used interchangeably, the order of parameters does not matter.

Does order of parameters matter in method signature?

The order of the parameters make a difference because it is a different signature. Imagine you had a human signature and altered the order of the letters, it would no longer be the same signature.


1 Answers

From the Java Language Specification (on Expressions):

15.7.4 Argument Lists are Evaluated Left-to-Right

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.

like image 166
Michael Easter Avatar answered Sep 23 '22 03:09

Michael Easter