Yes, it is possible for Java methods to have more than 255 local variables. The wide
opcode instruction can be used to modify an iload
or aload
instruction to use a 16-bit index instead of an 8-bit index, meaning that you can have up to 65536 different local variables in a function, as long as the wide
opcode ends up getting used.
That said, note that Java local variables do not necessarily correspond one-to-one with JVM local variables. It's possible that the Java compiler could look at your code, notice that space for locals can be reused in some contexts, then map multiple Java locals to the same JVM local variables.
Hope this helps!