search

Home  >  Q&A  >  body text

Java 中 boolean 出现 等于1是什么鬼?

  1. 今天无意间查看BigDecimal类,debug的时候发现方法中定义了一个boolean类型的变量的值居然是1,在Java中boolean不应该不是true就是false吗?否则编译都是错的啊。

  2. 代码如下:

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

PHP中文网PHP中文网2770 days ago1069

reply all(5)I'll reply

  • 黄舟

    黄舟2017-04-18 10:29:40

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

    reply
    0
  • PHPz

    PHPz2017-04-18 10:29:40

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

    reply
    0
  • 大家讲道理

    大家讲道理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

    reply
    0
  • 怪我咯

    怪我咯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

    reply
    0
  • 阿神

    阿神2017-04-18 10:29:40

    Reference mysql tinyint?

    reply
    0
  • Cancelreply