Java 中 boolean 出现 等于1是什么鬼?
PHP中文网
PHP中文网 2017-04-18 10:27:40
0
5
1097
  1. 今天无意间查看BigDecimal类,debug的时候发现方法中定义了一个boolean类型的变量的值居然是1,在Java中boolean不应该不是true就是false吗?否则编译都是错的啊。

  2. 代码如下:

  3. 求知道答案的同学讲解一波,实在是迷糊了。

PHP中文网
PHP中文网

认证0级讲师

reply all(5)
黄舟

len <= MAX_COMPACT_DIGIST Isn’t this just a boolean value, maybe because of the debug expression,

PHPzhong

Boolean in Java is stored in int after compilation. Maybe the debugger you use displays the actual value

大家讲道理
boolean isCompact =(len <= MAX_COMPACT_DIGIST);

This code will first execute the following len <= MAX_COMPACT_DIGIST. This is of bool type
So there is nothing wrong with the assignment here.
Secondly, computers don’t know true and false. This concept is artificially added. If you have studied C, you should know that non-0 is extremely true. Generally speaking, 1 is considered true and 0 is false. In fact, 2, 3, and 4 are considered true. . . It's also true.
So don’t panic if bool type numbers are printed during the debugging process

刘奇

1. I’m curious what IDE you use, IntelliJ IDEA?

2. If you don’t want anything to happen, let’s start with the orthodox and powerful Eclipse! Look, it’s quite normal if this doesn’t appear

阿神

Reference mysql tinyint?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template