今天无意间查看BigDecimal类,debug的时候发现方法中定义了一个boolean类型的变量的值居然是1,在Java中boolean不应该不是true就是false吗?否则编译都是错的啊。
代码如下:
求知道答案的同学讲解一波,实在是迷糊了。
黄舟2017-04-18 10:29:40
len <= MAX_COMPACT_DIGIST Isn’t this just a boolean value, maybe because of the debug expression,
PHPz2017-04-18 10:29:40
Boolean in Java is stored in int after compilation. Maybe the debugger you use displays the actual value
大家讲道理2017-04-18 10:29:40
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
怪我咯2017-04-18 10:29:40
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