Maximum number of parameters in Java method declaration

That limit is defined in the JVM Specification:

The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3.3), where the limit includes one unit for this in the case of instance or interface method invocations.

Section §4.3.3 gives some additional information:

A method descriptor is valid only if it represents method parameters with a total length of 255 or less, where that length includes the contribution for this in the case of instance or interface method invocations.

The total length is calculated by summing the contributions of the individual parameters, where a parameter of type long or double contributes two units to the length and a parameter of any other type contributes one unit.

Your observations were spot on, double word primitives (long/double) need twice the size of usual 4 bytes variables and 4 bytes object instance references.

Regarding the last part of your question related to 64bit systems, the specification defines how many units a parameter contribute, that part of the specification must still be complied with even on a 64bit platform, the 64bit JVM will accomodate 255 instance parameters (like your 255 Strings) regardless of the internal object’s pointer size.

Leave a Comment