Why was L
chosen as the prefix for references in type signatures? Does L
stand for something, like B
stands for byte
, and I
stands for int
? Or was it chosen because C
was already assigned to char
?
For example,
System.out.println( new String[0].getClass().getName() );
Yields:
[Ljava.lang.String;
I'm already aware of the explanations in the Java spec and the Class.getName method javadoc.
This character stem from JVM internal signature and class name representation.
See JVM Specification §4.3.2. Field Descriptors:
B byte signed byte C char Unicode character code point in the Basic Multilingual Plane, encoded with UTF-16 D double double-precision floating-point value F float single-precision floating-point value I int integer J long long integer L ClassName ; reference an instance of class ClassName S short signed short Z boolean true or false [ reference one array dimension
The array type consist of a [
for each dimension, followed by their element signature, e.g. [I
for int[]
. Similiarly, Object[]
is represented by [Ljava/lang/Object;
internally.
It seems, when the conversion from internal class name to application visible name, i.e. returned by Class.getName()
was first implemented, it was implemented as just converting /
to .
but without care for the array notation. Later on, it wasn’t changed for compatibility reasons.
Note the Java 8 introduced getTypeName()
to solve the issue, i.e. String[].class.getTypeName()
yields java.lang.String[]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With