简体   繁体   中英

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. However, when I run the exact code in an online Java compiler here , I get different results. A Long object seems to occupy 24 bytes.

Furthermore, the author says an empty String object occupies 40 bytes memory. However, the online compiler says it occupies 24 bytes.

Why could this be happening? Has there been an update to the Java compiler?

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.

The author clearly states:

Note: The following results are based on Sun's JDK 1.3.1 for Windows. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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