问题描述
请看下面的图片。
当我们用java创建一个带有new关键字的对象时,我们从操作系统获取一个内存地址。
Please look at the picture below.When we create an object in java with new keyword, we are getting a memory address from the OS.
当我们写时.println(objName)
我们可以看到一个特殊字符串作为输出。我的问题是:
When we write out.println(objName)
we can see a "special" string as output. My questions are:
- 这是什么输出?
-
如果是内存地址操作系统给我们的信息:
- What is this output?
If it is memory address which given by OS to us:
a)如何将此字符串转换为二进制文件?
a) How can I convert this string to binary?
b)如何获得一个整数变量地址?
b) How can I get one integer variables address?
推荐答案
这是类名和以@字符分隔。标识哈希码表示的是特定于实现的。它通常是对象的初始内存地址,但随着时间的推移,VM可以在内存中移动对象。所以(简而言之)你不能依赖它。
That is the class name and System.identityHashCode() separated by the '@' character. What the identity hash code represents is implementation-specific. It often is the initial memory address of the object, but the object can be moved in memory by the VM over time. So (briefly) you can't rely on it being anything.
在Java中获取变量的内存地址是没有意义的,因为JVM可以自由地实现对象和移动它们看似合适(你的对象可能/将在垃圾收集等过程中移动。)
Getting the memory addresses of variables is meaningless within Java, since the JVM is at liberty to implement objects and move them as it seems fit (your objects may/will move around during garbage collection etc.)
将为您提供二进制形式的整数。
Integer.toBinaryString() will give you an integer in binary form.
这篇关于Java中变量的内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!