为什么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);
    }
}

并收到以下错误消息

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).

在面向对象的编程语言中有一个很长的方法,有很少的理由。

翻译自:https://stackoverflow.com/questions/5689798/why-does-java-limit-the-size-of-a-method-to-65535-byte

转载注明原文:为什么Java将方法的大小限制为65535字节?