为什么Java将方法的大小限制为65535字节? [英] Why does Java limit the size of a method to 65535 byte?
本文介绍了为什么Java将方法的大小限制为65535字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚编译了以下代码
public class A {
public static void main(String... args) {
int i = 3;
++i;
++i;
++i;
++i;
++i;
++i;
++i;
++i;
// repeat writing the expression ++i for 20,000 times
System.out.println(i);
}
}
并收到以下错误消息
方法main(String ...)的代码是
超过65535字节限制
The code of method main(String...) is exceeding the 65535 bytes limit
为什么Java实现此限制?我没有看到理性,因为Java确实包含了goto_w指令。
Why does Java implement this limit? I don't see the rational since Java does include a goto_w instruction.
推荐答案
参见 Java虚拟机规范第4.10节:
4.10 Java虚拟机的限制
- 每个代码的数量非本地非抽象方法由Code属性(第4.7.3节)的exception_table,LineNumberTable属性(第4.7.8节)和LocalVariableTable属性中的索引大小限制为65536字节( §4.7.9)。
有一个很好的理由让一个方法长在一个对象中面向编程语言。
There's few good reasons to have a method that long in an object-oriented programming language.
这篇关于为什么Java将方法的大小限制为65535字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文