variadic functions - Which part of the Java Language Specification describes the behaviour of omitted varargs? -


i looking relevant portion of java language specification (jls) describes behaviour when invoking variable arity (vararg) method.

consider method:

public static void printvarargs(string... args) {     system.out.println(arrays.tostring(args)); } 

if invoke method so:

printvarargs(); 

the output like: [] because omission of args @ call site has been converted empty array in printvarargs method.

i looking point of jls defines behaviour. closest have found 15.12.4.2 evaluate arguments, doesn't give example, , i'm not sure if case covered formal/mathematical description.

which part of jls describes automatic creation of empty array when vararg omitted?

the text of jls section says:

if method being invoked variable arity method (§8.4.1) m, has n > 0 formal parameters. final formal parameter of m has type t[] t, , m being invoked k >= 0 actual argument expressions.

if m being invoked kn actual argument expressions, or, if m being invoked k != n actual argument expressions , type of kth argument expression not assignment compatible t[], argument list (e1, ... , en-1, en, ...ek) evaluated if written (e1, ..., en-1, new t[]{en, ..., ek}).

in case talking about, there k == n - 1 formal arguments, en, ..., ek empty sequence, , means argument evaluated if (e1, ..., en-1, new t[]{}).

in other words, behaviour specified in section looking at.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -