How does Swift "implicitly deployed options" differ from Java "autoboxing" integers?

Is the Swift idea of ​​“implicitly deployable options” the same as Java “autoboxing” integers? The following runtime exception is only possible in Swift if xObjan "implicitly deployed variant" is declared:

Integer xObj = new Integer(-1);  
xObj = null;  // could do this with an implicitly unwrapped optional as well.
Integer.valueOf(xObj); // <-- exception. Integer.valueOf(int x); couldn't deal with this.

The bottom line is that “implicitly expandable options” MAY be zero, but you'd better be careful and not use them when a non-null reference is expected, right?

+4
source share
1 answer

Swift " " , Java "autoboxing" ?

? . . , ? .

Java :

  • () , , ArrayList HashMap.

    • , , byte, short, int, long, float, double, boolean char. , . Java , Swift .
    • Swift , .
    • . Swift , Java, NSNumber.
    • Swift - , , , .
  • . null -1, Integer.MIN ..

    • , Swift.
+2

Source: https://habr.com/ru/post/1650486/


All Articles