我有一个具有 255 个参数的构造函数(用于自动生成的类)。在带有 javac 1.6.0_02 的 linux 上使用 ant。该类编译良好,一切都很好。
但是,当我尝试使用 jdk 1.6 在 windows xp 上的 eclipse 中编译相同的类时,出现以下错误
Too many parameters, parameter BLAH is exceeding the limit of 255 words eligible for method parameters
BLAH
是第 256 个参数。
有没有办法克服这个问题?更改自动生成的类不是一个选项,因为我需要在每次编译或更改生成器时更改它。这两个选项都 Not Acceptable ,因为我们已经可以在 linux 上获得此类。
PS:对于那些感兴趣的人,java 类是使用 JacORB 从 IDL 文件生成的。不幸的是,类中的参数数量无法减少,因为它定义了我们的软件和其他系统之间的接口(interface)。
最佳答案
好吧,你正在破坏 VM specification, section 4.10 :
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. Note that a method descriptor is defined in terms of a notion of method parameter length in which a parameter of type long or double contributes two units to the length, so parameters of these types further reduce the limit.
我建议您克服更改生成代码的障碍...老实说,我很惊讶它能在 Linux 上运行。如果它生成的字节码完全无效,我不会完全感到惊讶,它恰好在此刻为您工作。
虽然尝试寻找与现有代码保持一致并忽略限制的方法总是很诱人,但我认为在这种情况下,您应该立即将注意力转向减少参数数量。
关于Java 编译错误 : Parameter x is exceeding the limit of 255 words,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1309230/