Java. Instance variable length [duplicate]
Possible Duplicates:
Does Java have a limit on the class name length? Max name length of variable or method in Java Java.Variable name length.
i stupid, i know, sorry...
i created this question Java.Variable name length, but here very bad example... so, i try create new question, i have this class:
class Test
{
int i=10;
public static void main(String args[])
{
System.out.println(new Test());
}}
where variable name is not 'i' but 'iiiiiii....' with length 65535 chars(iiiiiiiiii...)
.class file have the same size that .java file. Compile - success.
but, when i>65535chars - Exception: UTF8 representation for string "iiiiiiiiiiiiiiiiiiii..." is too long for the constant pool
bingo!
What conclusion can we do?
unlimited-length - not 100% correct.
But i find some information that its problem not java language - its some problems with classfile, so somebody know: Whose problem?
It appears that this question has been asked at least a couple of times ("Max name length of variable or method in Java", "Does Java have a limit on the class name length?").
The best answer seems to be that while the Java Language Specification does not place a limit on constant, class or variable names, the Java Virtual Machine Specification (specifically, the classfile format) imposes a limit of 65535 characters. See section 4.10 of the JVM Specification, last bullet item.
Ok. We can't name variables with more than 65534 chars. But who cares?
精彩评论