java - boolean 数据类型如何在 Java 内部工作?

标签 java boolean

<分区>

当您将值“true”分配给 Java 中的 boolean 数据类型(例如 boolean variableName = true;)时,实际分配给该变量的值是什么?

最佳答案

Java Virtual Machine Specification section 2.3.4 中的状态:

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 encodes boolean array components using 1 to represent true and 0 to represent false. Where Java programming language boolean values are mapped by compilers to values of Java Virtual Machine type int, the compilers must use the same encoding.

关于java - boolean 数据类型如何在 Java 内部工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44729056/

相关文章:

python - 不是 bool 不起作用,而是 bool != True 起作用

objective-c - 从 plist 文件恢复 NSDictionary 中的 BOOL

java - 线程中的异常 "main"java.lang.IndexOutOfBoundsException : Index: 10, 大小:0

java - 在应用程序上下文中添加 applicationContext-dao.xml 和 applicationContext-service.xml 背后的原因是什么

c# - 以 ^Bo 开头的字符串

c++ - 为什么我的代码应该显示 "Yes"却显示 "No"?

javascript - 为什么 "or"可以工作,但 "and"不在我的 Ember.CompulatedProperty 中?

java - 如何使用定义的对象作为输入变量?

java - Java 中的链接方法 JSONObject/JSONArray

Java jackson : serialize a class with two field instead of all class