java - Java中变量名的长度限制

标签 java compiler-construction

<分区>

Possible Duplicate:
Max name length of variable or method in Java

我正在阅读 java 文档,它说“变量的名称可以是任何合法的标识符——Unicode 字母和数字的无限长度序列……”在 C++ 中,变量名称长度约为 255 个字符,具体取决于编译器,所以这在 Java 中是如何处理的?编译器会在 x 个字符后截断变量名吗?如果这是真的,那么 x 是什么?

最佳答案

根据 the class file format spec (在第 4.11 节下):

The length of field and method names, field and method descriptors, and other constant string values is limited to 65535 characters by the 16-bit unsigned length item of the CONSTANT_Utf8_info structure (§4.4.7). Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.

这也适用于局部变量,因为 LocalVariableTable指向变量名称的 CONSTANT_Utf8_info 值。

关于java - Java中变量名的长度限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8782465/

相关文章:

java - Play Framework - 如何从父类(super class)继承?

java - 为什么在实例上调用方法时不需要导入类(Java)

c++ - GCC 选项 : warning on non-void functions without a return statement

compiler-construction - 无类型 Lambda 演算的函数式语言

java - 使用 java 解析 xml 文件——基于 android 的应用程序

java - 关于 Java 泛型下限用法 : ? super T

java - 我可以在我的 Web 应用程序中同时使用 Spring 和 JSF 吗

java - 从 Java 调用 Python

c++ - 使用 boost spirit x3 进行语义检查

c - 为什么未使用的变量不好?