why varargs in java should be last parameter?
Ever wondered why varargs should be the last parameter? Found the solution at stackoverflow. Excerpt from the post is below
It follows the C convention. The C convention in turn is based on CPU architectures which pass arguments on the stack. The first non-vararg arguments end up at a fixed offset in the stackframe. If you could put the vararg arguments first, the stack offset of the following arguments would depend on how many vararg parameters you would have passed. This would greatly complicate the amount of code needed to access them.
Leave a Reply