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

      可以将整数值分配给 char 但不能将整数变量分配

      时间:2023-07-28
      • <bdo id='pRpPv'></bdo><ul id='pRpPv'></ul>

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

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

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

            1. <tfoot id='pRpPv'></tfoot>

                  <tbody id='pRpPv'></tbody>
              • 本文介绍了可以将整数值分配给 char 但不能将整数变量分配给 char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                为什么下面的代码编译不出来

                Why doesn't the following code compile

                int n = 5;
                char c = n;
                

                但以下确实编译

                char c = 5;
                

                我不是在这两种情况下都给 char 分配了一个整数值吗?

                Aren't I just assigning an integer value to char in both cases?

                推荐答案

                可以将 char 分配给 int 而无需强制转换,因为这是一种扩大转换.反过来,将 int 转换为 char 需要强制转换,因为它是一种缩小转换.

                A char can be assigned to an int without a cast because that is a widening conversion. To do the reverse, an int to a char requires a cast because it is a narrowing conversion.

                另请参阅 JLS.第 5 章.转化和促销.

                这篇关于可以将整数值分配给 char 但不能将整数变量分配给 char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如果 char 数组是 Java 中的 Object,为什么打印它不 下一篇:Java 在字符串中看不到空格

                相关文章

                最新文章

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

                    <tfoot id='CgbeY'></tfoot>