为什么L是引用类型的前缀(而不是其他一些字母)? [英] Why is L the prefix for reference types (instead of some other letter)?

查看:157
本文介绍了为什么L是引用类型的前缀(而不是其他一些字母)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 L 被选为类型签名中引用的前缀? L 代表什么,例如 B 代表字节代表 int ?或者是因为 C 已经分配给 char

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?

例如,

System.out.println( new String[0].getClass().getName() );

收益率:

[Ljava.lang.String;

我已经知道 Java规范 Class.getName方法 javadoc。

I'm already aware of the explanations in the Java spec and the Class.getName method javadoc.

推荐答案

此字符源于JVM内部签名和类名表示。

This character stem from JVM internal signature and class name representation.

参见 JVM规范§4.3.2。字段描述符



  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

数组类型包含每个维度的 [ ,然后是他们的元素签名,例如 [I for int [] 。同样, Object [] [Ljava / lang / Object; 内部表示。

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.

看来,当从内部类名转换为应用程序可见名称,即由 Class.getName()返回时,首先实现的是实现为只将 / 转换为但不关心数组表示法。稍后,由于兼容性原因,它没有更改。

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.

注意Java 8引入了 getTypeName() 解决问题,即 String [] .class.getTypeName() yield java.lang.String []

Note the Java 8 introduced getTypeName() to solve the issue, i.e. String[].class.getTypeName() yields java.lang.String[].

这篇关于为什么L是引用类型的前缀(而不是其他一些字母)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆