java引用变量,Java中的引用变量里面有什么?

We know that the object reference variable holds bits that represent a way to access an object.

It doesn't hold the object itself, but it holds something like a pointer or an address.

I was going through the Head-First Java (2nd edition) book and in the book it is written (in Chapter 3, page 54) that

In Java we don't really know what is

inside a reference variable. We do

know that whatever it is, it

represents one and only one object.

And the JVM knows how to use the

reference to get to the object. -

I want to ask:

Do an object reference variable holds pointer, address or what?

How does JVM interpret that?

解决方案

It's entirely up to the JVM to determine what goes inside a reference.

In the simplest case it would just be a pointer (i.e. an address). In more sophisticated cases, the VM may use different representations depending on the situation - for example, you may want to read the paper on "Compressed oops in HotSpot" to see how the HotSpot VM can avoid doubling the size of references in some (but not all) places when running as a 64-bit VM.

The important thing is that you should neither know nor care. As far as you're concerned as a programmer, it's just an opaque set of bits - its only purpose is to let you get to the object in question (or identify a null reference).

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值