参考stackoverflow中的回答 Size of a byte in memory - Java,注意标注高亮的部分 。说完byte、char、short,我们再来看看对于 boolean 的描述,摘取部分信息 2.3.4. The boolean Type:
更多对基本类型的描述,可以查看Primitive Data Types
Although the Java Virtual Machine defines a boolean type, it only provides very limited support for it. There are no Java Virtual Machine instructions solely dedicated to operations on boolean values. Instead, expressions in the Java programming language that operate on boolean values are compiled to use values of the Java Virtual Machine int data type.翻译大概如下:
The Java Virtual Machine does directly support boolean arrays. Its newarray instruction (§newarray) enables creation of boolean arrays. Arrays of type boolean are accessed and modified using the byte array instructions baload and bastore (§baload, §bastore).
In Oracle’s Java Virtual Machine implementation, boolean arrays in the Java programming language are encoded as Java Virtual Machine byte arrays, using 8 bits per boolean element.
尽管Java虚拟机定义了一种 boolean 类型,但对它的提供支持非常有限,没有专门的虚拟机指令用来操作 boolean 类型 。但是,对于有 boolean 值参与运行的表达式,都会被编译成 int 类型的数据 。所以虚拟机规范是这样定义的:boolean 单独使用时,占 4 字节,在数组中使用时,占 1 字节 。但最终如何实现,还是要看各个虚拟机厂商是否遵守规范了 。
虚拟机直接支持了 boolean 数组,它使用newarray指令来创建数组,并可以使用 baload 和 bastore 来访问和修改 boolean 类型的数组
在 Oracle 的Java虚拟机实现中,boolean 类型的数组被编码成和 byte类型的数组,每个 boolean 元素使用 8 bit 。
推荐阅读
- 「PHP编程」为什么使用composer下载的包,不需要再include?
- 淘宝卖家动态评分为什么会自动下降 淘宝动态评分一直下降
- 淘宝号为什么会降权要注意哪些 淘宝号降权是怎么导致的
- 苹果的静音键为什么不取消?苹果除了静音键还可以怎么取消静音?
- 炸花生为什么要放蒜头?
- 淘宝店库存为什么不能改 淘宝修改库存有影响吗
- 晚上喝红茶会水肿么。为什么[红茶]
- 古人喝茶为什么加盐,为什么喝茶要趁热
- 顾渚紫笋为什么不出名,顾渚紫笋的鉴别方法
- 专升本为什么逐渐减少?
