How many parameters are available for varargs object in java?
Yes there is. Try to allocate memory that is larger than your Pergemn memory that is throwing away OutOfMemory
.
Note that there is no information about array or varargs here. You are free to use your memory under the memory you allocated.
I hope this is just for teaching and not for using these many in your application.
source to share
Varargs is syntactic sugar for an on-the-fly array that is large enough to fit the encoded elements.
The limit will then be the size of the array, which is 2 31 (i.e. large).
Considering the size is determined by the actual number of parameters encoded, you never have to worry about that.
A quick test confirms that the normal method parameter 255 does not apply to individual varargs.
source to share
There is no explicit limit to the number of arguments for the arity variable. However, the size of the method is limited. It should not exceed 65535 byte codes .
When javac
compiles the call to the arity variable method, it creates and populates the array using a template like:
+0: dup
+1: bipush <index> (or sipush if index > 127)
+3: iconst_0
+4: iastore
+5: dup
...
So, filling one element of the array takes 5 or 6 byte codes.
This means that you can actually call the method with just over 10K arguments .
source to share