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

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

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

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

      1. Java中的整数和int有什么区别?

        时间:2023-10-01
        1. <legend id='X79ln'><style id='X79ln'><dir id='X79ln'><q id='X79ln'></q></dir></style></legend>

          • <bdo id='X79ln'></bdo><ul id='X79ln'></ul>
            <tfoot id='X79ln'></tfoot>

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

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

                1. 本文介绍了Java中的整数和int有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  例如为什么你可以这样做:

                  For example why can you do:

                  int n = 9;
                  

                  但不是:

                  Integer n = 9;
                  

                  你可以这样做:

                  Integer.parseInt("1");
                  

                  但不是:

                  int.parseInt("1");
                  

                  推荐答案

                  int 是原始类型.int 类型的变量存储您要表示的整数的实际二进制值.int.parseInt("1") 没有意义,因为 int 不是 一个类,因此没有任何方法.

                  int is a primitive type. Variables of type int store the actual binary value for the integer you want to represent. int.parseInt("1") doesn't make sense because int is not a class and therefore doesn't have any methods.

                  Integer 是一个类,与 Java 语言中的任何其他类没有什么不同.Integer 类型的变量将 references 存储到 Integer 对象,就像任何其他引用(对象)类型一样.Integer.parseInt("1") 是对 Integer 类的静态方法 parseInt 的调用(注意这个方法实际上返回一个 int 而不是 Integer).

                  Integer is a class, no different from any other in the Java language. Variables of type Integer store references to Integer objects, just as with any other reference (object) type. Integer.parseInt("1") is a call to the static method parseInt from class Integer (note that this method actually returns an int and not an Integer).

                  更具体地说,Integer 是一个具有 int 类型的单个字段的类.此类用于需要将 int 视为任何其他对象的情况,例如在泛型类型或需要可空性的情况下.

                  To be more specific, Integer is a class with a single field of type int. This class is used where you need an int to be treated like any other object, such as in generic types or situations where you need nullability.

                  请注意,Java 中的每个原始类型都有一个等效的 wrapper 类:

                  Note that every primitive type in Java has an equivalent wrapper class:

                  • byteByte
                  • shortshort
                  • intInteger
                  • longLong
                  • booleanBoolean
                  • charCharacter
                  • floatFloat
                  • doubleDouble
                  • byte has Byte
                  • short has Short
                  • int has Integer
                  • long has Long
                  • boolean has Boolean
                  • char has Character
                  • float has Float
                  • double has Double

                  包装类继承自 Object 类,而原始类不继承.所以它可以用在带有对象引用或泛型的集合中.

                  Wrapper classes inherit from Object class, and primitive don't. So it can be used in collections with Object reference or with Generics.

                  从 java 5 开始,我们有了自动装箱,原始类和包装类之间的转换是自动完成的.但是要小心,因为这可能会引入细微的错误和性能问题;明确说明转化永远不会受到伤害.

                  Since java 5 we have autoboxing, and the conversion between primitive and wrapper class is done automatically. Beware, however, as this can introduce subtle bugs and performance problems; being explicit about conversions never hurts.

                  这篇关于Java中的整数和int有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:整数包装对象仅在值 127 内共享相同的实例? 下一篇:value &amp; 是什么意思?0xff 在 Java 中做什么?

                  相关文章

                  最新文章

                  <tfoot id='pPMXJ'></tfoot>

                    <bdo id='pPMXJ'></bdo><ul id='pPMXJ'></ul>
                  1. <legend id='pPMXJ'><style id='pPMXJ'><dir id='pPMXJ'><q id='pPMXJ'></q></dir></style></legend>

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

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