如何在java中的内存中表示null [英] How is null represented in memory in java

查看:564
本文介绍了如何在java中的内存中表示null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Java内存中究竟是什么空白

有没有人知道如何在内存中为对象或任何东西表示空值。在dot net中,它由空指示符布尔值和相应类型的值表示(请参阅此处)。所以有人知道它是如何在java中完成的吗?

Does anyone know how a null value is represented in the memory for an object or anything. In dot net it is represented by null indicator Boolean value and value of the corresponding type (Refer here). So does any one know how it is done in java ??

推荐答案

来自 JVM规范,第2.4节


Java虚拟机规范没有强制要求编码null的具体值。

The Java virtual machine specification does not mandate a concrete value encoding null.

所以可能可以是任何东西,但它很可能是一个全零的参考值。引用本身可以是简单的指针(即,只是一个虚拟地址,与本机指针一样,具有适当的体系结构大小),但同样不必如此。一些JVM具有处理引用的非常智能的方法 - 例如,Hotspot是在许多情况下能够使用32位值作为引用,即使在x64进程中运行

So it could be anything, but it's very likely to be a reference value which is all zeroes. References themselves can be simple pointers (i.e. just a virtual address in the same way as a native pointer, of the appropriate size for the architecture) but again don't have to be. Some JVMs have very smart ways of handling references - for example, Hotspot is able to use 32-bit values for references in many situations, even when running in an x64 process.

这篇关于如何在java中的内存中表示null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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