Can any one tell the bit size of boolean in Java?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Size of the boolean in java is virtual machine dependent. but Any Java object is aligned to an 8 bytes granularity. A Boolean has 8 bytes of header, plus 1 byte of payload, for a total of 9 bytes of information. The JVM then rounds it up to the next multiple of 8. so the one instance of java.lang.Boolean takes up 16 bytes of memory.
It's virtual machine dependent.
It depends on the virtual machine, but it's easy to adapt the code from a similar question asking about bytes in Java:
To reiterate, this is VM-dependent, but on my Windows laptop running Sun's JDK build 1.6.0_11 I got the following results:
That suggests that booleans can basically be packed into a byte each by Sun's JVM.
I read that Java reserves one byte for a
boolean
datatype, but it uses only one bit. However, the documentation says that "its "size" isn't something that's precisely defined". See here.It's undefined; doing things like Jon Skeet suggested will get you an approximation on a given platform, but the way to know precisely for a specific platform is to use a profiler.
The
boolean
values are compiled toint
data type in JVM. See here.