本文介绍了Java中的字节默认情况下占用4个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I read this in an article. I am just pasting as is:
这是真的Java字节分配/需要4个字节吗?而空类需要8个字节?
这里也很混乱。
Is it true Java byte allocates / takes 4 bytes? and empty class takes 8 bytes?Its confusing here as well.
推荐答案
这是假的,至少对于HotSpot JVM来说是错误的。在那里,类中的原始字节字段将占用一个字节,但是类的实例的大小确实从8个字节开始,并且字段被分组为每个占用8个字节的块 - 例如,您可以不要在8字节边界上分割字段。
That is false, at least for the HotSpot JVM. There, a primitive byte field in a class will take one byte, but it is true that the size of an instance of a class starts at 8 bytes, and fields are grouped into chunks that take eight bytes apiece -- for example, you can't split a field across an 8-byte boundary.
参见eg
这篇关于Java中的字节默认情况下占用4个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!