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, hasn > 0formal parameters. final formal parameter ofmhas typet[]t, , m being invokedk >= 0actual argument expressions.if m being invoked kn actual argument expressions, or, if m being invoked
k != nactual argument expressions , type of kth argument expression not assignment compatiblet[], 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
Post a Comment