java - The var args parameters should be last in parameter list -


this question has answer here:

public void test(int... integers, string str) { // error    ...   } 

error:

the variable argument type int of method test must last parameter.

public void test(string str, int... integers) {} 

it works well. there reason this?

well, consider method signature:

public void test(int... integers, float val, float val2) 

now, when invoke method:

test(2, 3, 4, 5, 6, 7); 

how compiler decide when stop adding arguments int... type parameter? remember, arguments evaluated left-to-right in java. why var-args should @ end. so, compiler can first assign fixed parameters, , rest of arguments, go var-args.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -