开发者

Java. Instance variable length [duplicate]

This question already has answers here: Closed 12 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜