java 符号引用_Java中的符号引用

如果你引用一些文章给你带来麻烦,这将是有帮助的.既然你没有,我将从

ldc的文档中猜出你可能引用的内容:

Otherwise,if the run-time constant pool entry is a symbolic reference

to a class (§5.1),then the named class is resolved (§5.4.3.1) and a

reference to the Class object representing that class,value,is

pushed onto the operand stack.

Otherwise,the run-time constant pool entry must be a symbolic

reference to a method type or a method handle (§5.1). …

该引用有一个链接到JVM规范(5.1)的另一部分,它描述了运行时常量池:

a run-time data structure that serves many of the purposes of the

symbol table of a conventional programming language implementation

这意味着运行时常量池包含有关符号形式的类的部分的信息:作为文本值.

所以,当ldc给一个类的“符号引用”时,它被赋予常量池中CONSTANT_Class_info结构的索引.如果您查看此结构的定义,您将看到它包含对该类名称的引用,也保存在常量池中.

TL; DR:“符号引用”是可用于检索实际对象的字符串.

一个例子:

if (obj.getClass() == String.class) {

// do something

}

成为以下字节码:

aload_1

invokevirtual #21; //Method java/lang/Object.getClass:()Ljava/lang/Class;

ldc #25; //class java/lang/String

if_acmpne 20

在这种情况下,ldc操作是指以符号方式存储的类.当JVM执行此操作码时,它将使用符号引用来标识当前类加载器中的实际类,并返回对类实例的引用.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值