Java中的引用变量里面有什么? [英] What's inside a reference variable in Java?

查看:237
本文介绍了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.

我正在阅读Head-First Java(第2版)一书并在书中写出(见第3章,第54页)那个

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


在Java中,我们并不知道引用变量中的
是什么。我们知道无论它是什么,
代表一个且只有一个对象。
并且JVM知道如何使用
引用来获取对象。 -

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. -

我想问:


  • 对象引用变量是否包含指针,地址或什么?

  • JVM如何解释它?

推荐答案

完全取决于JVM来确定引用内部的内容。

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

在最简单的情况下,它只是指针(即地址)。在更复杂的情况下,VM可能会根据具体情况使用不同的表示形式 - 例如,您可能希望阅读HotSpot中的压缩oops,以了解当作为64位VM运行时,HotSpot VM如何避免在某些(但不是全部)位置加倍引用的大小。

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).

这篇关于Java中的引用变量里面有什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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