search

Home  >  Q&A  >  body text

java 类型是直接使用基本类型还是就干脆直接用java.lang的类型

比如:

Integer => int
Boolean => boolean
...

黄舟黄舟2771 days ago1115

reply all(14)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:08:18

    Divide into different scenes

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:08:18

    jdk 1.5. There is an automatic unboxing and packing mechanism. The purpose is to cater to the core idea of ​​​​Java, everything is an object.
    Therefore, during development, if the performance requirements are not very high, it is recommended to use the packaging class in the java.lang package.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:08:18

    Depends on the specific needs, but I personally always give priority to using basic types, because they take up less space. Compared with packaging types, their construction speed is also faster. Compared with packaging types, they are objects. , Secondly, the packaging classes provide static methods that can construct the packaging type from the basic type, so if you need to use the packaging type again, just convert it immediately.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:08:18

    1. In many cases, only Integer can be used, such as List<Integer>.

    2. Use int for temporary variables, such as for(int i=0;;)

    3. is aligned with other variables. If you see the following code, you will vomit blood.

    class O{
        int i;
        Integer j;
    }

    reply
    0
  • Cancelreply