<bdo id='sGH7c'></bdo><ul id='sGH7c'></ul>
  • <legend id='sGH7c'><style id='sGH7c'><dir id='sGH7c'><q id='sGH7c'></q></dir></style></legend>

    1. <i id='sGH7c'><tr id='sGH7c'><dt id='sGH7c'><q id='sGH7c'><span id='sGH7c'><b id='sGH7c'><form id='sGH7c'><ins id='sGH7c'></ins><ul id='sGH7c'></ul><sub id='sGH7c'></sub></form><legend id='sGH7c'></legend><bdo id='sGH7c'><pre id='sGH7c'><center id='sGH7c'></center></pre></bdo></b><th id='sGH7c'></th></span></q></dt></tr></i><div id='sGH7c'><tfoot id='sGH7c'></tfoot><dl id='sGH7c'><fieldset id='sGH7c'></fieldset></dl></div>
    2. <small id='sGH7c'></small><noframes id='sGH7c'>

        <tfoot id='sGH7c'></tfoot>
      1. 为什么 == 对于某些 Integer 对象为真?

        时间:2023-05-29
      2. <i id='ZM7Eq'><tr id='ZM7Eq'><dt id='ZM7Eq'><q id='ZM7Eq'><span id='ZM7Eq'><b id='ZM7Eq'><form id='ZM7Eq'><ins id='ZM7Eq'></ins><ul id='ZM7Eq'></ul><sub id='ZM7Eq'></sub></form><legend id='ZM7Eq'></legend><bdo id='ZM7Eq'><pre id='ZM7Eq'><center id='ZM7Eq'></center></pre></bdo></b><th id='ZM7Eq'></th></span></q></dt></tr></i><div id='ZM7Eq'><tfoot id='ZM7Eq'></tfoot><dl id='ZM7Eq'><fieldset id='ZM7Eq'></fieldset></dl></div>

              • <legend id='ZM7Eq'><style id='ZM7Eq'><dir id='ZM7Eq'><q id='ZM7Eq'></q></dir></style></legend>
              • <small id='ZM7Eq'></small><noframes id='ZM7Eq'>

                  <bdo id='ZM7Eq'></bdo><ul id='ZM7Eq'></ul>
                • <tfoot id='ZM7Eq'></tfoot>
                    <tbody id='ZM7Eq'></tbody>
                  本文介绍了为什么 == 对于某些 Integer 对象为真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能重复:
                  整数包装器对象仅共享相同的实例在值 127 以内?

                  我从 Khalid Mughal SCJP 复制了以下程序片段,但我无法
                  理解输出.

                  I have copied the following program snippet from the Khalid Mughal SCJP, but I am unable to
                  understand the output.

                   public class RQ200_60 {
                      public static void main(String[] args) {
                          Integer i = -10;
                          Integer j = -10;
                          System.out.print(i==j);         // output: true -- why true?
                          System.out.print(i.equals(j));  // output: true
                          Integer n = 128;
                          Integer m = 128;
                          System.out.print(n==m);         // output: false
                          System.out.print(n.equals(m));  // output: true
                      }
                  }      
                  

                  上面的程序为第一个打印语句给出了输出 true,但它应该给出 false,因为它是与 == 关系运算符的引用比较.但是第三次打印给出了错误,我不明白这种不一致.

                  The above program giving output true for the first print statement but it supposed to give false because it is reference comparison with == relational operator. But third print gives false and I don't understand this inconsistency.

                  非常感谢您的解释!

                  推荐答案

                  在第一种情况下,对象 ij 都指向同一个缓存对象.默认情况下,-128 到 127 之间的范围被缓存为 Integer 对象.我们可以使用 JVM arguments

                  In the first case, both the objects i and j are pointing to the same cached object. By default, the range between -128 and 127 are cached as Integer Object. We can increase the range using JVM arguments

                  这篇关于为什么 == 对于某些 Integer 对象为真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在Java中从String中获取int,也包含字母 下一篇:为什么 int j = 012 给出输出 10?

                  相关文章

                  <tfoot id='htlSg'></tfoot>
                  <i id='htlSg'><tr id='htlSg'><dt id='htlSg'><q id='htlSg'><span id='htlSg'><b id='htlSg'><form id='htlSg'><ins id='htlSg'></ins><ul id='htlSg'></ul><sub id='htlSg'></sub></form><legend id='htlSg'></legend><bdo id='htlSg'><pre id='htlSg'><center id='htlSg'></center></pre></bdo></b><th id='htlSg'></th></span></q></dt></tr></i><div id='htlSg'><tfoot id='htlSg'></tfoot><dl id='htlSg'><fieldset id='htlSg'></fieldset></dl></div>
                    <bdo id='htlSg'></bdo><ul id='htlSg'></ul>

                • <small id='htlSg'></small><noframes id='htlSg'>

                      <legend id='htlSg'><style id='htlSg'><dir id='htlSg'><q id='htlSg'></q></dir></style></legend>