是否可以在 Java 中找到非原始变量的地址? [英] Is it possible to find the address of a non-primitive variable in Java?

查看:27
本文介绍了是否可以在 Java 中找到非原始变量的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Integer i = 88i所在的内存地址是多少?

If Integer i = 88, what is the memory address i resides at?

此外,如果作为 Debugger 的一部分,id 编号发生变化,是否表明创建了一个新对象?

Additionally, if as part of Debugger, id number changes, is it indicative of the fact that a new object was created?

推荐答案

您的第二个问题的答案是肯定的,您在 Eclipse 调试器中看到的id"唯一地标识了一个对象,因此它的更改意味着一个新对象创建.因此,例如:

The answer to your second question is yes, the "id" you see in Eclipse's debugger uniquely identifies an object and so a change in it means a new object was created. So, for example:

Integer i = 55;
Integer j = new Integer(55);
Integer k = Integer.valueOf(55);

这里 i 和 k 将具有相同的 id,因为它们指向同一个对象;j 会有所不同.

Here i and k will have the same id, since they refer to the same object; j will be different.

这些对象之一的内存地址并不是真正有用的信息,因为对象在内存中移动.你所能知道的是,如果 i == k,它们是同一个对象.(所以在这里,i == k 但 i != j).

The memory address of one of these objects is not really a useful piece of information, since objects move around in memory. All you can know is that if i == k, they are the same object. (So here, i == k but i != j).

这篇关于是否可以在 Java 中找到非原始变量的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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