久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='2Ghal'><tr id='2Ghal'><dt id='2Ghal'><q id='2Ghal'><span id='2Ghal'><b id='2Ghal'><form id='2Ghal'><ins id='2Ghal'></ins><ul id='2Ghal'></ul><sub id='2Ghal'></sub></form><legend id='2Ghal'></legend><bdo id='2Ghal'><pre id='2Ghal'><center id='2Ghal'></center></pre></bdo></b><th id='2Ghal'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2Ghal'><tfoot id='2Ghal'></tfoot><dl id='2Ghal'><fieldset id='2Ghal'></fieldset></dl></div>

      <tfoot id='2Ghal'></tfoot>
        <bdo id='2Ghal'></bdo><ul id='2Ghal'></ul>
    1. <legend id='2Ghal'><style id='2Ghal'><dir id='2Ghal'><q id='2Ghal'></q></dir></style></legend>

      <small id='2Ghal'></small><noframes id='2Ghal'>

      1. Java 允許將字節分配給 java.lang.Short 但不能分配給

        Java allows to assign byte to java.lang.Short but not to java.lang.Integer(Java 允許將字節分配給 java.lang.Short 但不能分配給 java.lang.Integer)
        1. <legend id='algch'><style id='algch'><dir id='algch'><q id='algch'></q></dir></style></legend>

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

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

                <tfoot id='algch'></tfoot>
                • 本文介紹了Java 允許將字節分配給 java.lang.Short 但不能分配給 java.lang.Integer的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  final byte b = 12;  
                  Short s = b;  
                  Integer i = b;
                  

                  對于 Short,程序編譯正常,但對于 Integer 編譯失敗,并顯示不兼容的類型"消息.

                  Program compiles fine for Short but for Integer compilation fails with "incompatible types" message.

                  我很難理解這種行為.對于這種特定情況,我找不到任何東西..

                  I am having difficult time trying to understand this behavior. I could not find anything for this specific scenario..

                  推薦答案

                  我試圖用更廣泛的賦值上下文來復制這個:

                  I attempted to duplicate this with a wider group of assignment contexts:

                  final byte b = 12;
                  Byte b2 = b;
                  Character c = b;  // Only an error if b isn't final
                  char c2 = b;      // Only an error if b isn't final
                  Short s = b;      // Only an error if b isn't final
                  short s2 = b;
                  Integer i = b;  // Error, as indicated in the question
                  int i2 = b;
                  Long l = b;     // Also an error
                  long l2 = b;
                  Float f = b;    // Also an error
                  float f2 = b;
                  Double d = b;   // Also an error
                  double d2 = b;
                  

                  不僅分配給 Integer,還分配給 FloatLongDouble 是也是一個錯誤.

                  Assigning not just to a Integer, but also to a Float, a Long or a Double is also an error.

                  有趣的是,如果 b 的原始聲明不是 final,那么將 Character 分配給一個 char,或者 Short 也會失敗.

                  Interestingly, if the original declaration of b was NOT final, then assigning to a Character, a char, or a Short fails also.

                  JLS 第 5.2 節 稍微闡明了賦值上下文及其允許的轉換的主題.

                  Section 5.2 of the JLS sheds a little light on the subject of assignment contexts and their allowed conversions.

                  分配上下文允許使用以下之一:

                  Assignment contexts allow the use of one of the following:

                  • 身份轉換(第 5.1.1 節)

                  • an identity conversion (§5.1.1)

                  一個擴大的基元轉換(§5.1.2)

                  a widening primitive conversion (§5.1.2)

                  擴大參考轉換 (§5.1.5)

                  a widening reference conversion (§5.1.5)

                  裝箱轉換(第 5.1.7 節)可選地后跟擴大參考轉換

                  a boxing conversion (§5.1.7) optionally followed by a widening reference conversion

                  一個拆箱轉換(第 5.1.8 節)可選地后跟一個加寬的原始轉換.

                  an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion.

                  這涵蓋了到更廣泛的原始變量的所有轉換,無論 b 是否為 final,這些都是允許的.(除非 b 為負數,否則對無符號 char(或 Character)的賦值將失敗.)繼續:

                  This covers all of the conversions to wider primitive variables, which are always allowed, whether b is final or not. (That holds unless b is negative, in which case the assignment to an unsigned char (or Character) would fail.) Continuing:

                  此外,如果表達式是 byte、short、char 或 int 類型的常量表達式(第 15.28 節):

                  In addition, if the expression is a constant expression (§15.28) of type byte, short, char, or int:

                  • 如果變量的類型是 byte、short 或 char,并且常量表達式的值可以在變量的類型中表示,則可以使用縮小原語轉換.

                  • A narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable.

                  如果變量的類型為:

                  • 字節和常量表達式的值可以用字節類型表示.

                  • Byte and the value of the constant expression is representable in the type byte.

                  Short 并且常量表達式的值可以用 short 類型表示.

                  Short and the value of the constant expression is representable in the type short.

                  字符和常量表達式的值可以用char類型表示.

                  Character and the value of the constant expression is representable in the type char.

                  因為bfinal,表達式b是一個常量表達式,可以從int 常量表達式 12bytecharshort 然后裝箱到 ByteCharacterShort,但奇怪的是,不是 Integer 或任何以上"的東西.我能想到的唯一可能的解釋是,不允許將受原始縮小轉換影響的常量表達式轉換為 IntegerLong浮點數,或雙數.

                  Because b is final, the expression b is a constant expression, allowing it to be narrowed from the int constant expression 12 to byte, char, or short and then boxed to Byte, Character, or Short, but strangely, not to Integer or anything "above". The only possible explanation I can think of is that constant expressions that are subject to a primitive narrowing conversion aren't specifically allowed to be converted to Integer, Long, Float, or Double.

                  如果 b 不是 final,則不允許緊跟裝箱,并且不能從 提升非常量表達式bytechar 也可以.

                  If b isn't final, then the narrowing followed by boxing isn't allowed, and a non-constant expression can't be promoted from byte to char either.

                  這篇關于Java 允許將字節分配給 java.lang.Short 但不能分配給 java.lang.Integer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)
                    1. <tfoot id='AcI5o'></tfoot>
                      <i id='AcI5o'><tr id='AcI5o'><dt id='AcI5o'><q id='AcI5o'><span id='AcI5o'><b id='AcI5o'><form id='AcI5o'><ins id='AcI5o'></ins><ul id='AcI5o'></ul><sub id='AcI5o'></sub></form><legend id='AcI5o'></legend><bdo id='AcI5o'><pre id='AcI5o'><center id='AcI5o'></center></pre></bdo></b><th id='AcI5o'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AcI5o'><tfoot id='AcI5o'></tfoot><dl id='AcI5o'><fieldset id='AcI5o'></fieldset></dl></div>

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

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

                          • <bdo id='AcI5o'></bdo><ul id='AcI5o'></ul>
                              <tbody id='AcI5o'></tbody>
                          • 主站蜘蛛池模板: 亚洲视频在线看 | 一二三四在线视频观看社区 | 激情欧美一区二区三区中文字幕 | 欧美成年人网站 | 一区二区影视 | 黄色小视频入口 | 最新中文字幕在线 | 精品国模一区二区三区欧美 | 久久国产香蕉 | 人人看人人爽 | 久久久久国产精品一区二区 | 欧美日韩在线免费 | 91免费版在线 | 婷婷桃色网 | 日韩中文av在线 | 狠狠干夜夜草 | 在线欧美a | 国产一区二区在线视频 | 99re热精品视频 | 欧美一级二级三级视频 | 国产色视频网站 | 人人干97 | 天天操天天射综合 | 国产美女一区 | 96国产精品久久久久aⅴ四区 | 欧美日一区二区 | 91资源在线| 亚洲午夜精品一区二区三区他趣 | 婷婷综合色 | 黄色网址在线免费播放 | 91视频大全| 亚洲精品在线免费观看视频 | 精品久久久久久久久亚洲 | 国产欧美一区二区三区在线看 | 日韩精品一区二区三区 | 日韩一级在线 | 亚洲成人激情在线观看 | 欧美日韩在线观看一区 | 精品一区二区在线观看 | 久久亚洲精品国产精品紫薇 | 亚洲欧美日韩系列 |