请问Boolean类型的位宽是多少啊??“boolean在编译的时候会由编译器编译成int型,而 boolean arrays编译时由编译器编码成byte arrays”这句话对吗??谢谢各位大侠指导下啊。

解决方案 »

  1.   

    JVM在处理boolean时会把它转换为int或byte 
    这要看具体的JVM的实现了
    false由0整数表示
    true用非零整数表示
    而涉及boolean的操作会使用int
    boolean数组用byte数组访问,但在堆里面,它可以表示为位域 
      

  2.   

    boolean就象硬币一样 只有正反两面 没有什么位宽 只是JVM在进行和、与、取反时为了对其进行操作,将true、false转化为int或byte
      

  3.   

    这从哪里可以看出来?
    看了Boolean的源代码,没发现int或byte,
    boolean的源代码看不到
      

  4.   

    这是底层JVM的实现 JDK代码里面应该是看不到的
    这是Boolean类里找出来的    /**
         * Returns a <tt>String</tt> object representing this Boolean's
         * value.  If this object represents the value <code>true</code>,
         * a string equal to {@code "true"} is returned. Otherwise, a
         * string equal to {@code "false"} is returned.
         *
         * @return  a string representation of this object. 
         */
        public String toString() {
    return value ? "true" : "false";
        }
        /**
         * The value of the Boolean.
         *
         * @serial
         */
        private final boolean value;
    在进行和、与等操作时是使用的JVM进行处理的,你可以反编译JVM的代码 那就看得到了 呵呵
      

  5.   

    如果你对想对底层JVM进行了解 你可以去看看《深入JAVA虚拟机(第2版)》这本书
      

  6.   

    如果boolean没有位宽的话,那么下面的语句
     
      boolean b;
      b=false;声明一个boolean变量时,JVM有没有为它分配空间a?? false是以什么形式赋给b的?以什么形式存放的a??