-1
Integer x1 = 3, x2; // boxing
int y1 = x1; // unboxing
x2 = x1 + (x1 / 2); 

Let's suppose we have the following code. Does the 3rd line need 2 unboxings for x1 or we just say its 1 unboxing for x1 and one boxing for the whole result to be assigned to x2?

Prestyy
  • 93
  • 1
  • 8

1 Answers1

0

There are IDE plugins, which can be used to demystify boxing and unboxing. This is your code:

   L0
    LINENUMBER 46 L0
    ICONST_3
    INVOKESTATIC java/lang/Integer.valueOf(I)Ljava/lang/Integer;
    ASTORE 1
   L1
    LINENUMBER 47 L1
    ALOAD 1
    INVOKEVIRTUAL java/lang/Integer.intValue()I
    ISTORE 3
   L2
    LINENUMBER 48 L2
    ALOAD 1
    INVOKEVIRTUAL java/lang/Integer.intValue()I
    ALOAD 1
    INVOKEVIRTUAL java/lang/Integer.intValue()I
    ICONST_2
    IDIV
    IADD
    INVOKESTATIC java/lang/Integer.valueOf(I)Ljava/lang/Integer;
    ASTORE 2
Serge Bogatyrev
  • 818
  • 4
  • 5