This question came up in Spring class, which has some rather long class names. Is there a limit in the language for class name lengths?
Does Java have a limit on the class name length?
29k views Asked by Eugene Katz At
4
There are 4 answers
5
On
65535 characters I believe. From the Java virtual machine specification:
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.
here:
https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html#88659
The Java Language Specification states that identifiers are unlimited in length.
In practice though, the filesystem will limit the length of the resulting file name.