3

According to this answer every object in Java is of the same size? Is the answer talking about the object itself or the reference to the object?

Here's the statement:

every object size is rounded to 16 bytes in Hotspot, so an object with a single byte field will take up precisely the same space as a single object with a long or double field;

I am completely baffled by the claim in this statement. So many upvotes to this answer further befuddled me.

Can some one please explain what is meant by the above statement?

  • 2
    Note that this specifically mentions HotSpot and does not necessarily apply to any other JVM implementation (not even to newer and/or older versions of HotSpot, or HotSpot on another platform). Numbers like these are always implementation specific. – Joachim Sauer Jun 8 '13 at 17:02
4

Rounded to a multiple of 16 bytes. Objects can be 16B, 32B, 48B, etc

  • Where is the term multiple mentioned? – Geek Jun 8 '13 at 16:26
  • 1
    @Geek, the multiple is implied. Carelessly worded, admittedly, but most people can read between the lines. – Karl Bielefeldt Jun 8 '13 at 16:32
  • 1
    "Every object size is rounded to X" means a multiple of X. X could be "integers" or "powers of 2" or whatever, and the syntax is the same. (What's implied is that it's rounded UP.) – DougM Jun 8 '13 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.