<tfoot id='xfy46'></tfoot>

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

      <small id='xfy46'></small><noframes id='xfy46'>

      • <bdo id='xfy46'></bdo><ul id='xfy46'></ul>
        <legend id='xfy46'><style id='xfy46'><dir id='xfy46'><q id='xfy46'></q></dir></style></legend>
      1. 将 char 传递给带有 int 参数的方法

        时间:2023-07-27

          <tfoot id='GaOvi'></tfoot>
              • <legend id='GaOvi'><style id='GaOvi'><dir id='GaOvi'><q id='GaOvi'></q></dir></style></legend>

                  <bdo id='GaOvi'></bdo><ul id='GaOvi'></ul>

                  <small id='GaOvi'></small><noframes id='GaOvi'>

                • <i id='GaOvi'><tr id='GaOvi'><dt id='GaOvi'><q id='GaOvi'><span id='GaOvi'><b id='GaOvi'><form id='GaOvi'><ins id='GaOvi'></ins><ul id='GaOvi'></ul><sub id='GaOvi'></sub></form><legend id='GaOvi'></legend><bdo id='GaOvi'><pre id='GaOvi'><center id='GaOvi'></center></pre></bdo></b><th id='GaOvi'></th></span></q></dt></tr></i><div id='GaOvi'><tfoot id='GaOvi'></tfoot><dl id='GaOvi'><fieldset id='GaOvi'></fieldset></dl></div>
                    <tbody id='GaOvi'></tbody>
                  本文介绍了将 char 传递给带有 int 参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  以下代码的输出是 123 因为 substring 从 beginIndex 到 EndIndex - 1.但是,我很惊讶 char 在这里被理解为 3 (int) 因为 substring 需要两个整数.这背后的概念是什么?

                  The output from the following code is 123 because substring takes from beginIndex to EndIndex - 1. However, I am surprised how char here is understood as 3 (int) because substring take two ints. What is the concept behind this?

                  String x = "12345";
                  char a = 3;
                  x = x.substring(0, a);
                  System.out.println(x);
                  

                  推荐答案

                  这可以追溯到 C,其中 char 本质上是一种窄整数类型,并在必要时隐式转换为 int.

                  This goes all the way back to C, where char is in essence a narrow integer type and gets implicitly converted to int whenever necessary.

                  在 Java 中,这在技术上称为扩展原语转换",并在 JLS 的第 5.1.2 节.

                  In Java, this is technically known as a "widening primitive conversion", and is covered in section 5.1.2 of the JLS.

                  这篇关于将 char 传递给带有 int 参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从long到int的可能有损转换,JAVA 下一篇:为什么不能分配 I &lt;?扩展类型>到&lt;类

                  相关文章

                  最新文章

                    1. <legend id='eC85Y'><style id='eC85Y'><dir id='eC85Y'><q id='eC85Y'></q></dir></style></legend><tfoot id='eC85Y'></tfoot>

                      <small id='eC85Y'></small><noframes id='eC85Y'>

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