Java: Out with the Old, In with the New

后端 未结 30 2014
遥遥无期
遥遥无期 2020-12-22 16:11

Java is nearing version 7. It occurs to me that there must be plenty of textbooks and training manuals kicking around that teach methods based on older versions of Java, whe

30条回答
  •  旧巷少年郎
    2020-12-22 16:34

    Explicit conversion between primitive and wrapper types (e.g. Integer to int or vice versa) which is taken care of automatically by autoboxing/unboxing since Java 1.5.

    An example is

    Integer myInteger = 6;
    int myInt = myInteger.intValue();
    

    Can simply be written as

    Integer myInteger = 6;
    int myInt = myInteger;
    

    But watch out for NullPointerExceptions :)

提交回复
热议问题