<small id='1dOax'></small><noframes id='1dOax'>

<tfoot id='1dOax'></tfoot>

<legend id='1dOax'><style id='1dOax'><dir id='1dOax'><q id='1dOax'></q></dir></style></legend>

  • <i id='1dOax'><tr id='1dOax'><dt id='1dOax'><q id='1dOax'><span id='1dOax'><b id='1dOax'><form id='1dOax'><ins id='1dOax'></ins><ul id='1dOax'></ul><sub id='1dOax'></sub></form><legend id='1dOax'></legend><bdo id='1dOax'><pre id='1dOax'><center id='1dOax'></center></pre></bdo></b><th id='1dOax'></th></span></q></dt></tr></i><div id='1dOax'><tfoot id='1dOax'></tfoot><dl id='1dOax'><fieldset id='1dOax'></fieldset></dl></div>
    • <bdo id='1dOax'></bdo><ul id='1dOax'></ul>
      1. Java中的整数和int有什么区别?

        What is the difference between Integer and int in Java?(Java中的整数和int有什么区别?)

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

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

              • <bdo id='OP6Js'></bdo><ul id='OP6Js'></ul>

                  本文介绍了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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                1. <tfoot id='g3isi'></tfoot>
                2. <i id='g3isi'><tr id='g3isi'><dt id='g3isi'><q id='g3isi'><span id='g3isi'><b id='g3isi'><form id='g3isi'><ins id='g3isi'></ins><ul id='g3isi'></ul><sub id='g3isi'></sub></form><legend id='g3isi'></legend><bdo id='g3isi'><pre id='g3isi'><center id='g3isi'></center></pre></bdo></b><th id='g3isi'></th></span></q></dt></tr></i><div id='g3isi'><tfoot id='g3isi'></tfoot><dl id='g3isi'><fieldset id='g3isi'></fieldset></dl></div>

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

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