在《Java虚拟机规范》给出了单个boolean占4个字节,和boolean数组1个字节的定义,具体还要看虚拟机实现是否按照规范来,所以1个字节、4个字节都是有可能的[3] References [1]官方文档的描述:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html [2]what-is-the-size-of-a-boolean-variable-...
stackoverflow就有关于boolean占几个字节的讨论。 what-is-the-size-of-a-boolean-variable-in-java 其中有一个高赞回答: class LotsOfBooleans{ boolean a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af; boolean b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, ...
在google中能查到一篇文章(原文地址:https://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java)。里面有个高手,通过实操测试了在Sun's JDK build 1.6.0_11环境下,boolean类型到底占几个字节,实操源码如下。 class LotsOfBooleans { boolean a0, a1, a2, a3, a4, a5, ...
看到Java的基本类型,突然想到boolean 占几个字节?第一反应:1byte。 不确定,查之。在这个帖子上讨论过: 但众说纷纭,没有一个令人信服的,唯一的线索是:boolean的大小JVM规范并没有指定。 最后在stackoverflow上找到答案(http://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-ja...
在google中能查到一篇文章(原文地址:https://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java)。里面有个高手,通过实操测试了在Sun's JDK build 1.6.0_11环境下,boolean类型到底占几个字节,实操源码如下。 classLotsOfBooleans{booleana0,a1,a2,a3,a4,a5,a6,a7,a8,a9...
从以上内容我们可以得知JAVA规范中没有定义boolean类型的大小。 这在stackoverflow中的这个问题有所提及 What is the size of a boolean variable in Java? 这里讲到 It'svirtualmachine dependent.// 由虚拟机自己实现 而我在其他地方查到了如下资料:
So there may be a variable of type Boolean. 17th Oct 2017, 4:03 PM deFault + 3 I'm just nitpicking to the fact that 'variable of type Boolean has a size of 1 bit in Java' and 'variable of type Boolean can hold 1 bit of information' are different things, and first one isn'...
1. Java boolean syntax Theboolean keywordcan be used as shown in given examples. //1. variable booleanisMajorVersion =false; //2. method parameters publicvoidsetValid(booleanvalid ) { //code } //3. method return type publicbooleanisValid() { ...
For example, you can use acomparison operator, such as thegreater than(>) operator, to find out if an expression (or a variable) is true or false: Example intx=10;inty=9;System.out.println(x>y);// returns true, because 10 is higher than 9 ...
The simplest data type available to you in Java is the primitive type boolean. A boolean variable has only two possible values, true or false, which are represented with reserved words. In some other languages, Boolean types take on values of 0 or 1; or, as in C/C++, 0 represents ...