gpt4 book ai didi

java - 为什么 Java 将方法的大小限制为 65535 字节?

转载 作者:IT老高 更新时间:2023-10-28 20:52:51 28 4
gpt4 key购买 nike

我刚刚编译了以下代码

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);
}
}

并收到以下错误消息

The code of method main(String...) is exceeding the 65535 bytes limit

Java 为什么要实现这个限制?由于 Java 确实包含 goto_w 指令,因此我没有看到合理性。

最佳答案

Java Virtual Machine Specification第 4.10 节:

4.10 Limitations of the Java Virtual Machine

  • The amount of code per non-native, non-abstract method is limited to 65536 bytes by the sizes of the indices in the exception_table of the Code attribute (§4.7.3), in the LineNumberTable attribute (§4.7.8), and in the LocalVariableTable attribute (§4.7.9).

在面向对象的编程语言中拥有这么长时间的方法的充分理由。

关于java - 为什么 Java 将方法的大小限制为 65535 字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5689798/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com