简体   繁体   English

Long和String对象的Java大小

[英]Java size of Long and String objects

Here , the author's tests say that Integer and Long objects occupy the same amount of memory, ie, 16 bytes. 在这里 ,作者的测试表明IntegerLong对象占用相同的内存量,即16个字节。 However, when I run the exact code in an online Java compiler here , I get different results. 但是,当我在此处的在线Java编译器中运行确切的代码时,会得到不同的结果。 A Long object seems to occupy 24 bytes. Long对象似乎占据了24个字节。

Furthermore, the author says an empty String object occupies 40 bytes memory. 此外,作者说一个空的String对象占用40个字节的内存。 However, the online compiler says it occupies 24 bytes. 但是,在线编译器说它占用24个字节。

Why could this be happening? 为什么会这样呢? Has there been an update to the Java compiler? Java编译器是否已更新?

Note : The author does note that their results are based on Sun's JDK 1.3.1 for Windows and warns that they may change. 注意 :作者确实注意到其结果基于Sun的Windows JDK 1.3.1,并警告其可能会更改。

The author clearly states: 作者明确指出:

Note: The following results are based on Sun's JDK 1.3.1 for Windows. 注意:以下结果基于Sun的Windows JDK 1.3.1。 Due to what is and is not guaranteed by the Java language and JVM specifications, you cannot apply these specific results to other platforms or other Java implementations. 由于Java语言和JVM规范可以保证和不能保证,您不能将这些特定结果应用于其他平台或其他Java实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM