2

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?

Community
  • 1
  • 1
user471011
  • 7,104
  • 17
  • 69
  • 97

2 Answers2

7

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.

Community
  • 1
  • 1
RobertB
  • 4,592
  • 1
  • 30
  • 29
2

Ok. We can't name variables with more than 65534 chars. But who cares?

Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132